PySimpleGUI / PySimpleGUI/PySimpleGUI

[Bug] Tabgroup element generate different kind of event value after new Tab added

Open
#6,645 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Port - TK
Dominant language
Python
Stars
13.8k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Type of Issue (Enhancement, Error, Bug, Question)

Bug


Operating System

WIN10

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Python version (sg.sys.version)

3.10.2

PySimpleGUI Version (sg.__version__)

4.61.0.206

GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)

8.6.12


Your Experience In Months or Years (optional)

5 Years Python programming experience

10+ Years Programming experience overall

Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
tkinter
Anything else you think would be helpful?
None


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
  • None of your GUI code was generated by an AI algorithm like GPT
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description

The event value of the TabGroup element is different between existing Tabs and new Tabs which is added by call method add_tab.

It should be caused by that the information of the new added Tab element missed to add into element.tab_index_to_key in method TabGroup.add_tab.

Code To Duplicate
import PySimpleGUI as sg

def tab(index):
    return sg.Tab(f"TAB {index}", [[sg.Text(f"This is Tab {index}")]], key=f"{index} TAB")

total = 2
layout = [[sg.TabGroup([[tab(index) for index in range(total)]], enable_events=True, key='TABGROUP')]]
window = sg.Window('Title', layout, finalize=True)
window['TABGROUP'].add_tab(tab(total))

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break
    print(event, values)

window.close()

Click each Tab to check the value for TabGroup element

TABGROUP {'TABGROUP': '1 TAB'}    # Key of Tab
TABGROUP {'TABGROUP': '0 TAB'}    # Key of Tab
TABGROUP {'TABGROUP': 'TAB 2'}    # Title of Tab
Screenshot, Sketch, or Drawing

image

Contributor guide

Open the contributing guide

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 with TabGroup.add_tab and the tab_index_to_key mapping identified in the issue, then run the provided tkinter reproducer. Done means selecting a tab added with add_tab reports its key consistently with the existing tabs rather than its title.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.