TomSchimansky / CustomTkinter

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

'name' is not a supported argument. #961

Open stzanos95 opened 1 year ago

stzanos95 commented 1 year ago

Hi everyone, Merry Christmas!

Big fan of CTK but it seems to me that you cannot name widgets using the 'name' keyword argument with CustomTkinter just like in Tkinter. This makes it impossible to use for large complex projects that require naming conventions or mappings across widgets. I'm trying to receive the checkbool from a ctk.CTkCheckbox by using the nametowidget(<name>) method:

import customtkinter as ctk

class Gui(ctk.CTk):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.title('test')
        self.geometry(f'{100}x{100}')

        self.checkbox = ctk.CTkCheckBox(self, text='Sensor reading', name='mysensor')
        self.checkbox.pack()
        print(self.nametowidget('mysensor').get())

if __name__ == "__main__":
    configurator = Gui()
    configurator.mainloop()

But I get the error:

Traceback (most recent call last):
  File "test.py", line 18, in <module>
    configurator = Gui()
  File "test.py", line 12, in __init__
    self.checkbox = ctk.CTkCheckBox(self, text='Sensor reading', name='mysensor')
  File "/lib/python3.8/site-packages/customtkinter/windows/widgets/ctk_checkbox.py", line 47, in __init__
    super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
  File "/lib/python3.8/site-packages/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py", line 48, in __init__
    check_kwargs_empty(kwargs, raise_error=True)
  File "/lib/python3.8/site-packages/customtkinter/windows/widgets/utility/utility_functions.py", line 18, in check_kwargs_empty
    raise ValueError(f"{list(kwargs_dict.keys())} are not supported arguments. Look at the documentation for supported arguments.")
ValueError: ['name'] are not supported arguments. Look at the documentation for supported arguments.

Is this supported in another way with another key? I cannot seem to get around this.

Cheers

jaypy98 commented 1 year ago

Thats a big throwback. I had the same problem and it shucks!

edit: i found a way to do it but it still not confortable. creating a funtion that takes two list, one of the names of the widgets and the other list being something like this widgets_default_name = [wname.winfo_name() for wname in widgets], then zip both list created in the same order. so when you call a widget name, it is going to return the name you did set manually. this works because tkinter asigne a unique name to each widget, even for tkinter widget. it will be something like this !ctklabel, !ctklabel2... and so on.

ElectricCandlelight commented 1 year ago

Out of curiosity why can't you just use self.checkbox.get()