python - Supposed to be global Tkinter-window 'not defined' -
i have written little tool simulates traffic light system gui. worked fine on windows python 2.7, since intended run on raspberry pi necessary re-write threading-part.
so trying put of stuff 1 method. still not able create tkinter-element outside method tkinter-window built. can tell me how fix code possible create elements methode? here's code:
class gui (threading.thread): def __init__(self): threading.thread.__init__(self) def run(self): global window window = tk() window.title('ampel gui') window = canvas(window, width=400, height=200) window.pack() button1 = button(window, text="press", command=lambda: pushbutton(25)) button1.pack() button1.place(x=190, y=70) button2 = button(window, text="press", command=lambda: pushbutton(12)) button2.pack() button2.place(x=115, y=160) (...) window.mainloop() @staticmethod def output(lampe, status): if status == 0: if lampe == 21: window.create_oval(140, 30, 160, 10, fill="#ffa6a6") if lampe == 20: window.create_oval(170, 30, 190, 10, fill="#fafaaa") (...) output(20,0)
and get:
line 120, in output window.create_oval(170, 30, 190, 10, fill="#fafaaa") nameerror: global name 'window' not defined
what should create oval intended?
Comments
Post a Comment