CustomTkinter
CustomTkinter copied to clipboard
Customtkinter bind method - Label bind?
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
Does it throw any errors? Also, why are you taking an argument e
in your lambda function if you're not using it?
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
The bind method will be implemented for all CTk widgets in the next major version 5.0.0, which will be released soon.
Binding is now implemented with version 5.0.2.