My program generates several graphs one at a time and each has a quit button.
The program pauses in mainloop
until I press the button, then generates the next graph.
I would like a way to programmatically press or invoke the action associated to that button, in this case root.quit()
I have tried calling invoke()
on the button but this doesn't work. My feeling is that the event is lost before mainloop
is started.
from tkinter import *
pause = False # passed in as an 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 everything is drawn
canvas.update()
if not pause:
# Invoke the button event so we can draw the next graph or exit
quit.invoke()
root.mainloop()