Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports Needed
- import customtkinter
- # Variables Needed
- clicks = 0
- # Define Function To Add To Counter
- def click_detected(event=None):
- # Grab Global Variable You Need To Modify When Function Is Called
- global clicks
- # Modify Variable/Data
- clicks = clicks + 1
- # Update Label To Show Correct Data
- label.configure(text=f'Times Pressed: {clicks}')
- # Return Variable
- return clicks
- # Define Instance
- root = customtkinter.CTk()
- # Bind Window To Detect Left Click
- root.bind("<Button-1>", click_detected)
- # Create Widgets Needed
- label = customtkinter.CTkLabel(root, text=f'Times Pressed: {clicks}', font=("Roboto", 12))
- # Place Widgets Within Window
- label.place(relx=0.5, rely=0.5, anchor='center')
- # Loop Instance
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment