PySimpleGUI icon indicating copy to clipboard operation
PySimpleGUI copied to clipboard

Enhancement - Demo Program

Open AndyMorris62 opened this issue 2 years ago • 1 comments

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.

AndyMorris62 avatar Mar 07 '23 18:03 AndyMorris62

Thank you for the submission. I'll give it a look this week.

PySimpleGUI avatar Mar 13 '23 13:03 PySimpleGUI