Home > Software engineering >  School assignment Tkinter with method triple button
School assignment Tkinter with method triple button

Time:02-20

all I need in tkinter help, cos when you click with mouse three times read as once in counter. I know about it. I tried a couple of methods in mouse-event and I try with My current code. Tnx for your help in advance

from tkinter import *
counter=0
def mouse_click(event):
    global counter
    print('Counter is ',counter)
    counter =1
    window = Tk()
    window.minsize(300, 100)
    label = Label( window, text="Click here")
    label.pack()
    label.bind( "<Double-Button>", mouse_click)
    window.mainloop()

I have found a solution to this code thanks to everyone who tried

from tkinter import  *
counter = 0

def mouse_click_times(event):
    global counter
    print("You press triple button times: ",counter)
    counter  =1

windows = Tk()
windows.minsize(400,250)
label = Label(windows, text = "Click me 3x: ",bg = "blue", fg = "white")
label.pack()
label.bind("<Triple-Button-1>",mouse_click_times)
windows["bg"]="green"
exit_from_tkinter_loop = Button(windows, text="Exit from window", bg = 
"blue", fg = "white",command=windows.destroy)
exit_from_tkinter_loop.pack(pady = 20)
windows.mainloop()

CodePudding user response:

The event Double-Button is fired for double clicks. If you want to count individual clicks, use Button

from tkinter import *

counter = 0


def mouse_click(event):
    global counter
    print('Counter is ', counter)
    counter  = 1


window = Tk()
window.minsize(300, 100)
label = Label(window, text="Click here")
label.pack()
label.bind("<Button>", mouse_click)
window.mainloop()

  • Related