TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
10.99k stars 1.04k forks source link

name argument for widgets. #419

Open jericjan opened 1 year ago

jericjan commented 1 year ago

In tkinter, you can give widgets names with the name argument. I noticed that I cannot do that with CustomTkinter. I mainly use it to find the widgets again with nametowidget() and then change their text. I've changed my code to use StringVars instead which was, in hindsight, what I should have done in the first place. So my problem is fixed but I'd still need the name argument still if, for example, I want to pack_forget() a widget through nametowidget().

jericjan commented 1 year ago

After looking into the code, I realized that the name actually does get set and creating a CTkLabel actually creates a tkinter.Frame with a tkinter.Label as its child. So instead of using .frame.my_widget_name I used .frame.!ctklabel.my_widget_name and it worked as it should.

jericjan commented 1 year ago

Nevermind, this becomes an issue when you pack multiple widgets in a row and you end up with widget path names such as .frame.!ctklabel and .frame.!ctklabel2. This can get annoying when you add widgets in the future and those path names change.

I made a pull request and it seems to be the fix. #422