CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

BUG ... MAIN BUG -button interaction-

Open kalle07 opened this issue 9 months ago • 4 comments

In Tkinter, the command associated with a button is only executed when the mouse button is released while the mouse pointer is still over the button. This behavior mimics the native GUI standards on platforms such as Windows and ensures that accidental clicks (e.g. pressing the button but dragging away before releasing it) do not trigger the action.

In contrast, CustomTkinter executes the button's command immediately when the mouse button is pressed, regardless of whether the cursor remains over the button when it is released. This subtle difference in interaction can affect the user experience, especially when trying to replicate the behavior of the native operating system.

to me, this is an internal BUG that can only be programmed by complicated commands like “mouse released” and “request coordinates”!

kalle07 avatar May 21 '25 21:05 kalle07

You could do workaround like this:

import customtkinter as tk

class ButtonStateApp(tk.CTk):
    def __init__(self):
        super().__init__()
        self.title("Button Release Check")

        self.button = tk.CTkButton(self, text="Press and Release Me")
        self.button.pack(pady=20)

        self.status_label = tk.CTkLabel(self, text="Button Status: Idle")
        self.status_label.pack()

        # Bind the <ButtonRelease-1> event (left mouse button release)
        self.button.bind("<ButtonRelease-1>", self.on_button_release)

    def on_button_release(self, event):
        self.status_label.configure(text="Button Status: Released")
        print("Button Released!")
        # Func()

if __name__ == "__main__":
    app = ButtonStateApp()
    app.mainloop()

FaheemM1020 avatar Sep 28 '25 04:09 FaheemM1020

Related to that, when using a ComboBox. Half of the time when selecting the dropdown, it selects the element that pops up behind the cursor. It happens mostly when the list is large, as it requires the list to appears under the cursor (in place / on top of the current combobox that was clicked). I guess this would require filling a separate issue (Especially in case this is unrelated).

antonio-fr avatar Sep 28 '25 22:09 antonio-fr

I use wxPython, no need for extra hacks ;)

kalle07 avatar Sep 29 '25 08:09 kalle07

will consider changing

TomSchimansky avatar Oct 12 '25 00:10 TomSchimansky