1
我的程序一次生成一个图形,每个图形都有一个退出按钮。 程序暂停在mainloop
,直到我按下按钮,然后生成下一个图。如何以编程方式通过tkinter画布退出主循环按钮
我想一种以编程方式按或调用关联到该按钮的动作,在这种情况下root.quit()
我已经打过电话上的按钮invoke()
但这不起作用。我的感觉是这个事件在mainloop
开始之前就已经丢失了。
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()