Guest User

Untitled

a guest
Jul 26th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. # Imports Needed
  2. import customtkinter
  3.  
  4. # Variables Needed
  5. clicks = 0
  6.  
  7. # Define Function To Add To Counter
  8. def click_detected(event=None):
  9. # Grab Global Variable You Need To Modify When Function Is Called
  10. global clicks
  11. # Modify Variable/Data
  12. clicks = clicks + 1
  13. # Update Label To Show Correct Data
  14. label.configure(text=f'Times Pressed: {clicks}')
  15. # Return Variable
  16. return clicks
  17.  
  18. # Define Instance
  19. root = customtkinter.CTk()
  20.  
  21. # Bind Window To Detect Left Click
  22. root.bind("<Button-1>", click_detected)
  23.  
  24. # Create Widgets Needed
  25. label = customtkinter.CTkLabel(root, text=f'Times Pressed: {clicks}', font=("Roboto", 12))
  26.  
  27. # Place Widgets Within Window
  28. label.place(relx=0.5, rely=0.5, anchor='center')
  29.  
  30. # Loop Instance
  31. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment