TomSchimansky / TomSchimansky/CustomTkinter

SegmentedButton in CTkTabview

Open
#1,880 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
13.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

SegmentedButton in CTkTabview behave differently than CTkSegmentedButton itself what is a bit misleading:

CTkSegmentedButton

app = customtkinter.CTk()
def segmented_button_callback(args):
    print("segmented button clicked:", args)
segemented_button = customtkinter.CTkSegmentedButton(app, values=["Value 1", "Value 2", "Value 3"], command=segmented_button_callback)
segemented_button.set("Value 1")
sgemented_button.grid(row=0, column=0)
app.mainloop()

SegmentedButton in CTkTabview

app = customtkinter.CTk()
def segmented_button_callback():
    print("segmented button clicked:")
tabview = customtkinter.CTkTabview(master=app, command=segmented_button_callback)
tabview.pack(padx=20, pady=20)
tabview.add("tab 1")  # add tab at the end
tabview.add("tab 2")  # add tab at the end
tabview.set("tab 2")  # set currently visible tab
app.mainloop()

In 2nd case CTkTabview do not pass current selected button/tab segmented_button_callback() no parameters are allowed. If I try use segmented_button_callback() like in 1st example, I got:

Traceback (most recent call last):
  File "C:\Users\mplic\.pyenv\pyenv-win\versions\3.11.1\Lib\tkinter\__init__.py", line 1948, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\mplic\Projects\venvs\dcspy_311\Lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 554, in _clicked
    self._command()
  File "C:\Users\mplic\Projects\venvs\dcspy_311\Lib\site-packages\customtkinter\windows\widgets\ctk_segmented_button.py", line 167, in <lambda>
    command=lambda v=value: self.set(v, from_button_callback=True),
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mplic\Projects\venvs\dcspy_311\Lib\site-packages\customtkinter\windows\widgets\ctk_segmented_button.py", line 381, in set
    self._command(self._current_value)
  File "C:\Users\mplic\Projects\venvs\dcspy_311\Lib\site-packages\customtkinter\windows\widgets\ctk_tabview.py", line 107, in _segmented_button_callback
    self._command()
TypeError: segmented_button_callback() missing 1 required positional argument: 'args'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the callback mismatch from the issue examples, then compare _segmented_button_callback in windows/widgets/ctk_tabview.py with set in windows/widgets/ctk_segmented_button.py. Check the existing callback behavior and related tests, if present; done means CTkTabview's segmented-button callback behavior is consistent with the documented API and the reproducer no longer raises TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
Half a day
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.