CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Binding mouse button to a label

Open miquelgs99 opened this issue 3 years ago • 2 comments

Hello, Custom Tkinter is a brilliant library, but I have an issue with binding the left button of the mouse to a label. I want that when you click in a piece of text, a function executes, but it's not working. It worked with normal Tkinter.

Here's an example:

    self.right_label = ctk.CTkLabel(top_text_frame, text='Sudoku', text_font=('Segoe UI', 15))
    self.right_label.grid(column=2, row=0, padx=20)

    self.right_label.bind("<Button-1>", lambda event, btn="right": self.change_to(btn))

And here's the function (it's not important):

def change_to(self, btn, event=None):

    if self.which_frame == "Coloring" and btn == "right":
        self.left_label.configure(foreground='black')
        self.mid_label.configure(text='Sudoku')
        self.right_label.configure(foreground='#F0F0F0')
        self.which_frame = "Sudoku"

        self.sudoku_frame.tkraise()

    elif self.which_frame == "Sudoku" and btn == "left":
        self.left_label.configure(foreground='#F0F0F0')
        self.mid_label.configure(text='Coloring')
        self.right_label.configure(foreground='black')
        self.which_frame = "Coloring"

miquelgs99 avatar Sep 23 '22 18:09 miquelgs99

Thank you!!!!

miquelgs99 avatar Sep 25 '22 15:09 miquelgs99

It will work in the next version 5.0.0, which will be released soon.

TomSchimansky avatar Oct 07 '22 14:10 TomSchimansky

Binding is now implemented with version 5.0.0.

TomSchimansky avatar Dec 06 '22 22:12 TomSchimansky