【发布时间】:2017-08-14 14:51:12
【问题描述】:
我的程序一次生成多个图表,每个图表都有一个退出按钮。
程序在mainloop 暂停,直到我按下按钮,然后生成下一个图表。
我想要一种以编程方式按下或调用与该按钮关联的操作的方法,在本例中为 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()
【问题讨论】:
标签: python-3.x canvas tkinter tkinter-canvas