python 3.x - How to programically quit mainloop via a tkinter canvas Button -
my program generates several graphs 1 @ time , each has quit button. program pauses in mainloop
until press button, generates next graph.
i way programmically press or invoke action associated button, in case root.quit()
i have tried calling invoke()
on button doesn't work. feeling event lost before mainloop
started.
from tkinter import * pause = false # passed in arg root = tk() root.title(name) canvas = canvas(root, width=canvas_width, height=canvas_height, bg = 'white') canvas.pack() quit = button(root, text='quit', command=root.quit) quit.pack() # make sure drawn canvas.update() if not pause: # invoke button event can draw next graph or exit quit.invoke() root.mainloop()
i realised problem event being lost , mainloop
blocking used pause
arg determine when run mainloop
, i.e. on last graph.
see tkinter understanding mainloop
all graphs displayed , when press quit on window windows disappear , program ends.
if there better way please let me know, works.
root = tk() root.title(name) # name passed in arg # creation of canvas , elements moved function draw( root, ... ) if not pause: root.update_idletasks() root.update() else: mainloop()
Comments
Post a Comment