PySimpleGUI / PySimpleGUI/PySimpleGUI

Enhancement - Demo Program

Open
#6,284 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Demo Programs 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)

Enhancement


Operating System

Wndows 10

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Version information can be obtained by calling sg.main_get_debug_data()
Or you can print each version shown in ()
Python Interpeter: C:\Users\AndyJ\AppData\Local\Programs\Python\Python311\python.exe
Python version: 3.11.1
Platform: Windows
Platform version: ('10', '10.0.19045', 'SP0', 'Multiprocessor Free')
Port: PySimpleGUI
tkinter version: 8.6.12
PySimpleGUI version: 4.60.4.145
PySimpleGUI filename: C:\Users\AndyJ\AppData\Local\Programs\Python\Python311\Lib\site-packages\PySimpleGUI\PySimpleGUI.py

Your Experience In Months or Years (optional)

Years Python programming experience
2 years
Years Programming experience overall
30 years
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)

Anything else you think would be helpful?


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
  • 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

demo program - Demo_Multiple_Windows_read_all_windows_25_lines.py - causes application error if a windows is closed when its not paused.
I have worked out a fix - pasted below.
I am not sure if thats the best way to do it, but it works as far as I can see

Code To Duplicate

A short program that isolates and demonstrates the problem (Do not paste your massive program, but instead 10-20 lines that clearly show the problem)

This pre-formatted code block is all set for you to paste in your bit of code:


# Paste your code here
#!/usr/bin/env python
"""
    Demo - Multiple read_all_window(timeout=20)
        A 2-window event loop run in async mode

    Super-simple, 25 lines of code.

    Copyright 2021 PySimpleGUI
"""

import PySimpleGUI as sg

sg.set_options(font='_ 18')

window1 = sg.Window('ONE', [[sg.T('Window 1',size=(30,1),k='-T-')],[sg.B('Run', k='-B-'), sg.B('Exit')]],
                    finalize=True,
                    metadata="Open")

window2 = sg.Window('TWO', [[sg.T('Window 2',k='-T-')],[sg.B('Run', k='-B-'),sg.B('Exit')]], finalize=True,
                    location=(window1.current_location()[0]-250,window1.current_location()[1]),
                    metadata="Open")

i, paused = 0, [False, False]

while True:             # Event Loop
    window, event, values = sg.read_all_windows(timeout=10)
    print(window, event, values) if event != sg.TIMEOUT_EVENT else None
    if window == sg.WIN_CLOSED and event == sg.WIN_CLOSED:
        window1.close()
        window2.close()
        sg.popup_auto_close('Exiting...')
        break
    if event in (sg.WINDOW_CLOSED, 'Exit'):
        window.metadata = 'Closed"'
        window.close()
        continue
    if (not paused[0]) and window1.metadata == 'Open':
        window1['-T-'].update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
    if (not paused[1]) and window2.metadata == 'Open':
        window2['-T-'].update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
    if event == '-B-':
        paused[0 if window == window1 else 1] = not paused[0 if window == window1 else 1]
        window['-B-'].update('Run' if not paused[0 if window == window1 else 1] else 'Pause')
    i += 1

Screenshot, Sketch, or Drawing

image


Watcha Makin?

If you care to share something about your project, it would be awesome to hear what you're building.

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 Demo_Multiple_Windows_read_all_windows_25_lines.py and run the provided two-window example with the tkinter port. Reproduce the application error by closing a window while it is not paused, then compare the behavior with the reported fix. Done means closing windows no longer causes the application error while the demo's event loop still exits correctly.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.