I’m trying to make a “auto clicker” button that adds a value every second.
This means I want the function to rerun to itself after waiting a second.
Although in customtkinter time.sleep() does not work, and I’ve seen that you can use the “after” function in tkinter, but I am unable to get it to work with customtkinter.
Help is appreciated!
import cutomtkinter
import time
count = 0
autoclick_value = 1.
class ButtonWindow(customtkinter.CTkFrame):
def init(self, master):
global count
super().init(master)
def auto_click():
global count
global autoclick_value
count += autoclick_value
self.click_display.configure(text=f"You have " + str(round(count, 2)) + " clicks")
time.sleep(1)
def click_counter():
global count
auto_click()
count += click_power
self.click_display.configure(text=f"You have " + str(round(count, 2)) + " clicks")
self.click_display = customtkinter.CTkLabel(self, text="You have " + str(round(count, 2)) + " clicks.")
self.click_display.grid(row=0, column=0)
self.Button = customtkinter.CTkButton(self, text="Click me", command=click_counter)
self.Button.grid(row=1, column=0)
Kooritsmani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.