Advertisement
Guest User

Untitled

a guest
May 26th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter.ttk import *
  3.  
  4. def plus_one():
  5. """adds 1 to the counter"""
  6. global click_counter, counter_label
  7.  
  8. click_counter += 1
  9. counter_label["text"] = str(click_counter)
  10.  
  11. def minus_one():
  12. """takes 1 away from the counter"""
  13. global click_counter, counter_label
  14.  
  15. click_counter -= 1
  16. counter_label["text"] = str(click_counter)
  17.  
  18. def main():
  19. """main function"""
  20.  
  21. global click_counter, counter_label
  22.  
  23. click_counter = 0
  24. window = Tk()
  25.  
  26. counter_label = Label(window, text=str(click_counter))
  27. counter_label.grid(row=0, column=0)
  28.  
  29. plus_one_button = Button(window, text="+1", command=plus_one)
  30. plus_one_button.grid(row=2, column=0)
  31.  
  32. minus_one_button = Button(window, text="-1", command=minus_one)
  33. minus_one_button.grid(row=2, column=1)
  34.  
  35. window.mainloop()
  36.  
  37. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement