CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Customtkinter bind method - Label bind?

Open galipyuksel opened this issue 2 years ago • 3 comments

self.label_3 = customtkinter.CTkLabel(master=self.frame, text="Register.", cursor="hand2") self.label_3.place(relx=0.5, rely=0.84, anchor=tkinter.CENTER) self.label_3.bind("<Button-1>", lambda e: self.openUrl)

Why didn't this code work for me? I click on the text but it doesn't work

galipyuksel avatar Aug 08 '22 17:08 galipyuksel

Does it throw any errors? Also, why are you taking an argument e in your lambda function if you're not using it?

TheFallen-Cat avatar Aug 10 '22 16:08 TheFallen-Cat

I am sorry for bumping an old thread, but I hope someone can help me. I have a similar issue where binding a label to a mouse button click just doesn't work. This is the code:

label_info_2 = customtkinter.CTkLabel(master=root, image=photo_4, text="[email protected]") label_info_2.grid(row=2, column=2, sticky="ne", padx=5, pady=20, columnspan=2) label_info_2.bind("<1>", copy_text)

def copy_text(event): print("something happened")

The code above does not work and there are no errors in the terminal. Things I have tried:

  • label_info_2.bind("<1>", lambda: copy_text) - does not work, again with no errors
  • label_info_2.bind("<1>", lambda event: copy_text(event)) - also does not work

I have tried the same thing with the regular tkinter label and that works:

label_info_2 = Label(master=root, image=photo_4, text="[email protected]") label_info_2.grid(row=2, column=2, sticky="ne", padx=5, pady=20, columnspan=2) label_info_2.bind("<1>", copy_text)

However, I want to use custom tkinter label and still have the click event. Is that not possible or am I doing something wrong? I really hope someone could assist me. Thanks image

slavoev avatar Sep 15 '22 16:09 slavoev

The bind method will be implemented for all CTk widgets in the next major 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.2.

TomSchimansky avatar Dec 06 '22 22:12 TomSchimansky