Answers for "tkinter while button not pressed"

0

tkinter while button not pressed

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()
Posted by: Guest on October-15-2021

Code answers related to "tkinter while button not pressed"

Python Answers by Framework

Browse Popular Code Answers by Language