I am trying to write a Python program to count how many times a button is clicked. I have written the following code:
import tkinter
from tkinter import ttk
def clicked(event):
event.x = event.x + 1
label1.configure(text=f'Button was clicked {event.x} times!!!')
windows = tkinter.Tk()
windows.title("My Application")
label = tkinter.Label(windows, text="Hello World")
label.grid(column=0, row=0)
label1 = tkinter.Label(windows)
label1.grid(column=0, row=1)
custom_button = tkinter.ttk.Button(windows, text="Click on me")
custom_button.bind("<Button-1>", clicked)
custom_button.grid(column=1, row=0)
windows.mainloop()
I know that event.x is used to capture the location of mouse. And hence the result of the program is not as expected. I want something else. Can you please help me solve the issue.