Repository navigation
Description
Type of Issue (Enhancement, Error, Bug, Question)
Question
Operating System
Windows 11
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 version (sg.sys.version)
3.12.1
PySimpleGUI Version (sg.__version__)
4.60.5
GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)
8.6.13
Your Experience In Months or Years (optional)
Years Python programming experience : just learning
Years Programming experience overall: 45 years
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine): no
Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
- [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
- [X ] None of your GUI code was generated by an AI algorithm like GPT
- [X ] If not tkinter - looked for Demo Programs for specific port
- [X ] For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
- [X ] Run your program outside of your debugger (from a command line)
- [X ] Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
- [X ] Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
- [X ] Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description
I am wanting to write a menu driven system that opens various windows, each with a menu in them.
I have written a different python file for each window, and I start with a main menu window.
With the main menu window open, I open a second window and it the second window works fine, but I cannot use any of the buttons on the first window until the second window is closed - it seems to buffer the instructions and it only performs them after the second window is closed.
Is there something I can do so that the user can swop between the open windows and use the full functionality of the open windows?
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:
import PySimpleGUI as sg
from try01 import fTry01
from try02 import fTry02
# the main program
def main():
mInputMain = [
[sg.Text('This is the main window')],
[sg.Button('Open 1', key='-OPEN01-')],
[sg.Button('Open 2', key='-OPEN02-')]
]
window = sg.Window('InputMain', mInputMain, location=(20, 0), resizable=True, finalize=True)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == '-OPEN01-':
fTry01()
elif event == '-OPEN02-':
fTry02()
window.close()
if __name__ == '__main__':
main()
# the code that calls a second window
import PySimpleGUI as sg
def fTry02():
mInput02 = [
[sg.Text('This is the second window that is being opened')],
[sg.Text('This will be the second line on the window')],
[sg.Input('', size=(12,1), enable_events=True, key='-INPUT02-')],
[sg.Button('Clear02', key='-CLEAR02-')]
]
window02 = sg.Window('Input02', mInput02, location=(400,400), resizable=True, finalize=True)
while True:
event, values = window02.read()
print(f'{event} was clicked')
if event == sg.WIN_CLOSED:
break
elif event == '-CLEAR02-':
print('clear02')
window02['-INPUT02-'].update('', background_color = 'red')
window02.close()Screenshot, Sketch, or Drawing
Watcha Makin?
I have written a system in Microsoft Excel (VBA) that plots the drift of an object in the sea so that we can search and find a casualty more easily. I am wanting to rewrite it so that it is independent of Microsoft, but also so that it can run cross-platform.
This is the reason that, at my ripe old age of over 70, I am learning python and wanted to use your wonderful PySimpleGUI
Regards, Marilyn

Activity
jason990420 commentedon Jan 6, 2024
You can find the execution of your script blocked in the event loop of your second window.
Not to add event loop for each window with
window.read, but only one event loop for all wondows withsg.read_all_windows.Example Code
[-]Question[/-][+][Question] How to work with multiple windows[/+]happymvd commentedon Jan 7, 2024
Thank you Jason for your quick response - I really appreciate it.
My system will have 7 main modules with lots of complicated code in 5 of them, so it would not be manageable to have all the code in one module.
To give you an idea of what I am needing -
a) a toolbox that has 9 different calculates and 6 different conversions
b) to build and maintain 3 different tables (input new records, change information, delete information)
c) to calculate where an object started drifting in the sea from what observers are seeing
d) to calculate how an object is drifting given the forecast conditions in the area
e) to calculate how an object has drifted using sample data
f) to calculate how best to search a "probable area of detection" offering 7 different patterns
g) to calculate how best to get a rescue team to the area
In a number of cases what appears on the screen will depend upon what the user is selecting and what the input and calculated data is showing - so to have the GUI code in one file independent of the python functions would make the logic and maintenance very complicated.
I would need the "a) toolbox" to be available from each of the other modules
PySimpleGUI commentedon Jan 7, 2024
Thank you Marilyn for calling PySimpleGUI "wonderful"
I'm inspired by your experience, ambitiousness, fearlessness! That's quite a project that you've described and quite a lot of programming in your lifetime.
For multiple windows, the
read_all_windowsis the best interface to use if you need multiple windows to be visible and interacted with simultaneously. If they are windows that will open sequentially, then it'll be both easier and you'll have more options available. Not everything works with read_all_windows.PySimpleGUI does quite a bit of work for you for things like building menus and windows so it'll save you time there. It's the coordination between your modules, the multiple windows, structuring your project, etc, that are going to be the challenges.
The narrower you can make your questions, the easier we'll be able to get you answers and respond quickly. It's difficult with a huge project to come in cold and try to help with questions that are outside the scope of PySimpleGUI itself.
The Demo Programs are likely the best place for you to get examples of ways to accomplish pieces of your project, including multiple windows. There is also the eCookbook that may be of help. https://eCookbook.PySimpleGUI.org . We're getting really close to being done with PySimpleGUI 5 which has the eCookbook in the main docs so that it's searchable and has better documentation overall. We'll do our best to support ya. Thanks for the compliments!
happymvd commentedon Jan 7, 2024
Again, thank you Jason ...... for your response, and also for your kind words .....
I am very impressed with the quick response and also the quality of the responses - so a big thank you for that.
I have spent today thinking hard about how to manage my problem, and I am certainly understanding that it would be easier to split my app into two apps ...... one with the toolbox, and then separately have the "searching" in an independent app. When my users need to use both, they can load both .......
I really like PySimpleGUI (even before I knew the support was great) .... it was simple and easy to learn and more powerful than what I looked at before. It is also nice to know that if I need to, I will be able to move to other platforms easily.
Yes, I have learnt a huge amount of the basics from the Demo Programs ..... they just did not illustrate the use of multiple windows open at the same time, all allowing the user to interact with them ...... now I know that at the moment that is not easy to achieve, I will replan and work around it.
I look forward to PySimpleGUI 5 ..... development never ends does it ..... that is what appeals to me and has taken me right through to my ripe old age. I am very lucky
Again, a big thanks
PySimpleGUI commentedon Jan 7, 2024
Hi Marilyn ... sorry about confusion that I've likely created. It's Mike that's using the PySimpleGUI GitHub account. Jason is the incredible software engineer that provides the best support for our users. So there's 2 of us that you'll find making comments. His response time is incredibly impressive! And he's a better programmer than I am for that matter 😉 We're incredibly fortunate to have his expertise. I've used his code to implement numerous features and fixes.
For Multiple Windows demo programs, try searching for
read_all_windowsin the Demo Browser.PySimpleGUI 5 has much better documentation and a lot of new features. We're getting really close, but the schedule keeps slipping. We're feature complete and testing at this point so it shouldn't be much longer. It's really motivating to hear from users like yourself! Thank you for taking the time to share your experience... great stuff to read.
-mike
eagleEggs commentedon Jan 7, 2024
Was cool to see another 'multiple windows' post. As a testament to PSG's solid code base and upgrade philosophy, my hacked up version of multiple windows from 5 years ago STILL works even with latest version of PSG. Great work!!! <3
That tool has maybe 6 windows, all usable. If it helps I can review the issue here and try to assist - Or pull the project in question and see if I can work on it. I know one of the workarounds was to rebuild the layouts in the main loop and re-assign/read the windows as separate variables.
PySimpleGUI commentedon Jan 7, 2024
I generally prefer the
read_all_windowsapproach as it has a lower chance of missing events or getting things out of order. The downside is a couple of features that were added to individual windows, but not to read all window. I don't recall exactly which at the moment. One may be the confirmation for closing. There's a possibility to get a work-around for that if needed.And it's awesome to hear from ya @eagleEggs !!