Advertisement
here2share

# tk_restart_gui_counter.py

Apr 15th, 2023
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # tk_restart_gui_counter.py
  2.  
  3. import tkinter as tk
  4.  
  5. class Cv:
  6.     counter = 0
  7. cv = Cv()
  8.    
  9. def create_gui(): # for quick debugging
  10.  
  11.     def restart():
  12.         cv.counter += 1
  13.         label.configure(text=f"Counter: {cv.counter}")
  14.         root.destroy()
  15.         create_gui()
  16.  
  17.     root = tk.Tk()
  18.     root.geometry("%dx%d+-10+0"%(200,200))
  19.     label = tk.Label(root, text=f"Counter: {cv.counter}")
  20.     label.pack()
  21.  
  22.     button = tk.Button(root, text="Restart", command=restart)
  23.     button.pack()
  24.  
  25.     root.bind('<space>', lambda event: restart())
  26.  
  27.     root.mainloop()
  28.  
  29. create_gui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement