📜  未按下按钮时的 tkinter - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:14.353000             🧑  作者: Mango

代码示例1
from tkinter import *

root = Tk()
root.geometry('250x250')

display = Label(root, text='Hello', font=('', 20))
display.pack(pady=40)

def restart():
    display['text'] = 'Restarting...'
    but['state'] = 'disable'            # Once restarted the button gets disabled

def cancel():
    # Cancel the current after with it id
    root.after_cancel(L)
    display['text'] = 'Cancelled'

# Take a reference of after
L = root.after(5000, restart)

but = Button(root, text='Cancel', command = cancel )
but.pack(side='bottom', pady=30)

mainloop()