Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Canvas refreshing problem
#1
Hello Guys. I have a problem about canvas. I work for lift program. When the lift move up or down, program should show number and arrow. I create program. But I can't direction arrow. My program shows to me "updateError" text(I establish this text. ) If lift is move up(travel_up) I should see upArrow2, If lift move down(travel_down) I should see downArrow2. Number is work good. Just I can't see arrow. How can I fix this?

 #! /usr/bin/python
# -*-coding: utf-8 -*-


#-Library setting-#
import RPi.GPIO as gpio
import time
import serial
from Tkinter import *
from ttk import Frame, Style, Button
from PIL import ImageTk, Image

#from PIL import Image as PilImage
import binascii

gpio.setmode(gpio.BCM)
gpio.setup(33, gpio.IN)

#-Buffer definition-#

dataarray=''
data=''
uartData=''
dstflg=False
dspflg=False
dataflg=False


#-Serial port config-#
try:
    stmSer=serial.Serial(port='/dev/ttyAMA0', baudrate=115200,
                  parity=serial.PARITY_NONE,
                  stopbits=serial.STOPBITS_ONE,
                  bytesize=serial.EIGHTBITS,
				  timeout=0.00001     
                  )
except serial.SerialException:
    print "Stmser except error"


#-GUI update according to data of 'CARSTAT'-#
def updateGUI(data):
    global left_character
    global right_character
    global call_up
    global call_down
    global travel_up
    global travel_down


    left_character=(data[10:12]).decode("hex")
    print "left_character:"+left_character
    right_character=(data[12:14]).decode("hex")
    print"right_character:"+right_character

    petra_status_1=format(ord(data[14:16].decode("hex")),'08b')
    print "status:"+petra_status_1

    
    travel_down=petra_status_1[4]
    travel_up=petra_status_1[3]
    
    print "UP:"+travel_up
    print "DOWN:"+travel_down

    katno.config(text=left_character+right_character, font=('Arial 300'))
    

        
    
    if travel_up=="1":
        canvas=Canvas(root, width=200, height=320, highlightthickness=0, bg='#2080FF')
        canvas.place(x=10, y=30)
        image=PhotoImage(file='/home/pi/Dekstop/upArrow2.png')
        #canvas.create_image(90,170, image='')
        canvas.update()
        #time.sleep(0.001)
        
        katno.config(text=left_character+right_character, font=('Arial 300'))
    elif travel_down=="1":
        canvas=Canvas(root, width=200, height=320, highlightthickness=0, bg='#2080FF')
        canvas.place(x=10, y=30)
        image=PhotoImage(file='home/pi/Dekstop/downArrow2.png')
        #canvas.create_image(90,170, image='')
        canvas.update()
        #time.sleep(0.001)
        katno.config(text=left_character+right_character, font=('Arial 300'))
    elif travel_up=="0" and travel_down=="0":
        
        #canvas=Canvas(root, width=200, height=320, highlightthickness=0, bg='#2080FF')
        #canvas.place(x=10, y=30)
        image=PhotoImage(file='')
        #canvas.create_image(90,170, image='')
        canvas.update()
        #time.sleep(0.001)
        katno.config(text=left_character+right_character, font=('Arial 300'))
    else:
        print "travel conditions ERROR"
        
        
    
    

    
    
    root.after(5,loop)
    
    
    
    
    
###-Data Read -#
def readuart():
    global dataread
    global datalist
    global dataarray
    global dstflg
    global dspflg
    
    while True:
        if stmSer.inWaiting()>0:
            dataread=stmSer.read(1)
            
            if dataread=='@' and dstflg==False:
               dstflg=True
               dspflg=False
               dataarray=''
            elif dataread=='$' and dspflg==False:
                dspflg=True
                dstflg=False
                #stmSer.write(dataarray)
                print "dataarray: "+dataarray
                
                return dataarray
                dataarray=''
            else:
                if dstflg==True and dspflg==False:
                    dataarray=dataarray+''.join(dataread)
                elif dstflg==True and dspflg==True:
                    print "Reset loop"
                    root.after(5,loop)
                else:
                    print "ERROR!!"
                    
                    
                input_value = gpio.input(33)    ##Button Pgm_DW
                if input_value == True:
                    dstflg==True
                    dspflg==True
                    print('The button has been pressed...')
        else:
            print "Data wait."
            

def prgloop():
    root.after(5,loop)
    

    
#-Furcation to update function  -#
def loop():
    global dataread
    global datalist
    global dataarray
    global dstflg
    global uartData
    global dspflg
    global data
    
    

    try:
        uartData=readuart() 
    
    
        if uartData[:8]=='CARSTAT,':
            updateGUI(uartData)
            print "data: "+uartData
        else:
            print "İnvalid Data"
            root.after(5,loop)        
    except:
        print "Update ERROR"
        prgloop()

    dspflg=False
     

#-Graphical Design-#
    
try:
    root=Tk()
    root.title('New Program')
    root.overrideredirect(0)
    
    katno=Label(root, text='1', font=('Arial 300'), width=2, fg='white', bg='#2080FF')
    katno.place(x=-90, y=-40)
    katno.config(padx=170)
    
    canvas=Canvas(root, width=200, height=320, highlightthickness=0, bg='#2080FF')
    canvas.place(x=10, y=30)
    image=PhotoImage(file='/home/pi/Desktop/downArrow2.png')
    canvas.create_image(90,170, image=image)
    
    root.configure(background='#2080FF')
    root.geometry('480x440+0+0')
    loop()
    root.mainloop()
except:
    print "errorGUI"
Thanks
Quote
#2
Faruk Wrote:My program shows to me "updateError" text
First replace
except:
    print "Update ERROR"
with
except Exception:
    print "Update ERROR"
    import traceback
    traceback.print_exc()
Quote
#3
(Dec-04-2018, 08:19 AM)Gribouillis Wrote:
Faruk Wrote:My program shows to me "updateError" text
First replace
except:
    print "Update ERROR"
with
except Exception:
    print "Update ERROR"
    import traceback
    traceback.print_exc()

Thanks for your reply. But program so slowly. I try use label add your suggestion my code. This so look good. Thanks
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 2,128 Jun-04-2019, 05:05 AM
Last Post: Gupi
  [Tkinter] Problem loading an image from directory into a Canvas object tiotony 3 798 Sep-02-2018, 06:47 PM
Last Post: woooee

Forum Jump:


Users browsing this thread: 1 Guest(s)