TomSchimansky / CustomTkinter

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

Setting border_width specifcation on CTkOptmenu errors (_tkinter.TclError: unknown option "-border_width") #499

Closed avalon60 closed 2 years ago

avalon60 commented 2 years ago

Adding a border to a CTkOptmenu widget, results in an error. This can be demonstrated, by taking the simple_example.py and changing the code, thus:

optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, border_width=1, values=["Option 1", "Option 2", "Option 42 long long long..."])

Error stack:

/home/clive/PycharmProjects/customtk/venv/bin/python /home/clive/PycharmProjects/customtk/simple_example.py
Traceback (most recent call last):
  File "/home/clive/PycharmProjects/customtk/simple_example.py", line 40, in <module>
    optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, border_width=3, values=["Option 1", "Option 2", "Option 42 long long long..."])
  File "/home/clive/PycharmProjects/customtk/venv/lib/python3.8/site-packages/customtkinter/widgets/ctk_optionmenu.py", line 38, in __init__
    super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs)
  File "/home/clive/PycharmProjects/customtk/venv/lib/python3.8/site-packages/customtkinter/widgets/widget_base_class.py", line 30, in __init__
    super().__init__(*args, width=width, height=height, **kwargs)  # set desired size of underlying tkinter.Frame
  File "/usr/lib/python3.8/tkinter/__init__.py", line 3124, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "/usr/lib/python3.8/tkinter/__init__.py", line 2572, in __init__
    self.tk.call(
_tkinter.TclError: unknown option "-border_width"
TomSchimansky commented 2 years ago

Thats a mistake in the documentation, the optionmenu has no attribute border_width. I decided not to have it, because with a border, the optionemnu would look the same as a combobox and you couldn't distinguish between them...

avalon60 commented 2 years ago

Ah... OK Tom, thanks. I also notice that the CTk() widget fails with "bg_color=" but that "bg=" works fine. Is this a docs issue?

TomSchimansky commented 2 years ago

The CTk has no bg_color just an fg_color. Because the fg_color is always the main foreground color, and the bg_color is the color of the element behind the widget. So the window has no bg_color because there's nothing behind it. But I mapped the bg and background arguments to fg_color in the beginning, because people are used to do it like this in tkinter. But I think I will remove them now and just use fg_color as the only valid argument to configure the window color.