Dec-03-2023, 09:41 AM
(Dec-22-2020, 07:11 PM)Ensaimadeta Wrote: Hello iMuny, thanks for your suggestion.
I have done as you suggested and still no luck...
This is how it looks now:
from serial import * from tkinter import * import time root = Tk() root.geometry("1280x800") root.attributes('-fullscreen',True) bg = PhotoImage(file = "/home/pi/Pictures/SCREEN2.png") canvas = Canvas( root, width = 1280, height = 800) canvas.pack(fill = "both", expand = True) canvas.create_image( 0, 0, image = bg, anchor = "nw") serialPort = "/dev/ttyUSB0" ser = Serial(serialPort, 9600, timeout=0) ser.flush() def split_coords(astring): a, b = astring.split(';') a = int(a) b = int(b) return (a, b) def paintRectangle1(canvas_ref): print("entered Rect 1") canvas_ref.create_rectangle(207, 151, 620, 374, fill='red') time.sleep(0.3) def paintRectangle2(canvas_ref): print("entered Rect 2") canvas_ref.create_rectangle(600, 120, 800, 220, fill='red') time.sleep(0.3) def paintRectangle3(canvas_ref): print("entered Rect 3") canvas_ref.create_rectangle(200, 260, 400, 360, fill='red') time.sleep(0.3) def paintRectangle4(canvas_ref): print("entered Rect 4") canvas_ref.create_rectangle(600, 260, 800, 360, fill='red') time.sleep(0.3) root.mainloop() while True: if ser.in_waiting> 0: line = ser.readline().decode('utf-8').rstrip() x, y = split_coords(line) print("x:", x, "- y:", y) canvas = Canvas( root, width = 1280, height = 800) if (x>19) and (x<60) and (y>20) and (y<40): print("OK button1") paintRectangle1(canvas) if (x>68) and (x<110) and (y>20) and (y<40): print("OK button2") paintRectangle2(canvas) if (x>19) and (x<60) and (y>45) and (y<80): print("OK button3") paintRectangle3(canvas) if (x>68) and (x<110) and (y>45) and (y<80): print("OK button4") paintRectangle4(canvas) ''' else: canvas.create_image( 0, 0, image = bg, anchor = "nw") '''and the error...
Error:x: 11 - y: 11 Traceback (most recent call last): File "/home/pi/Documents/Touch-GUI-TKInter_4.py", line 55, in <module> canvas = Canvas( root, width = 1280, height = 800) File "/usr/lib/python3.7/tkinter/__init__.py", line 2405, in __init__ Widget.__init__(self, master, 'canvas', cnf, kw) File "/usr/lib/python3.7/tkinter/__init__.py", line 2299, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError: can't invoke "canvas" command: application has been destroyed
same here. did you found the solution