如何在多次单击按钮后销毁窗口(使用tkinter)?

时间:2015-04-09 14:48:24

标签: python-3.x tkinter

import tkinter as tk
def rand1():
    global rand_called
    rand_called += 1
rand_called = 0
games_number = int(input('How many games would you like to play? '))
m_gui = tk.Tk()
button1 = tk.Button(m_gui, text = 'Door 1', fg = 'green', bg = 'red', command = rand1)
button1.place(x = 20,y = 30)

我希望在m_gui推送button1次之后销毁games_number窗口。 我试过这个:

while True:
    if rand_called > games_number:
        m_gui.destroy()
        break
m_gui.mainloop()

但它无法完成这项工作。

请帮帮我

1 个答案:

答案 0 :(得分:2)

您需要将逻辑放在rand1

def rand1():
    global rand_called
    rand_called += 1
    if rand_called > games_number:
        m_gui.destroy()