![]() Here is an example from Demo_Design_Pattern_Multiple_Windows.py: import PySimpleGUI as sgĭemo - 2 simultaneous windows using read_all_windowīoth windows have buttons to launch popups. It is mentioned in their Cookbook and in their demos on Github. PySimpleGUI has a recommended method for working with multiple windows. The Traditional Multiple Window Design Patter Depending on what the user chooses, the conditional will print out something different. This Window calls read() directly and closes when the user chooses "Yes", "No" or exits the Window. In this example, when you click the "Open Window" button, it creates the secondary Window in a conditional statement. Here is one way to do that: import PySimpleGUI as sg ![]() If you're not going to have a lot of widgets in the second Window, then you can create the Window as a one or two-liner. You don't have to write a completely separate function for your secondary Window. Now let's look at a way that you can shorten your code if you are creating a simple Window like the one above. That means you cannot interact with the first Window until you close the second one. This second window has a parameter named modal in it that is set to True. If you click on the "Open Window" button, you will get a new Window that looks like this: When you run this code, you will see a small Main Window that looks like this: Window = sg.Window("Main Window", layout) If event = "Exit" or event = sg.WIN_CLOSED: Window = sg.Window("Second Window", layout, modal=True) You can create two Windows and show them both at the same time in PySimpleGUI like this: import PySimpleGUI as sg For example, a modal dialog might be used to ask the user if they really want to Exit your program or to display an end-user agreement (EULA) dialog. This is useful when you want to force the user to read something or ask the user a question. A Modal Window won't let you interact with any other Windows in your program until you exit it. PySimpleGUI provides a Window Element that you use to display other Elements in, such as buttons, text, images, and more. You can use pip for that: python -m pip install pysimplegui Making a Window Modal ![]() You will want to install PySimpleGUI to get started using it. You can read more about it in my Intro to PySimpleGUI or in my article for Real Python, PySimpleGUI: The Simple Way to Create a GUI With Python. It wraps other Python GUIs and gives them a common interface. PySimpleGUI is one of the easiest Python GUIs to get started with. In this tutorial, you will learn how to create two windows with PySimpleGUI. When you are creating graphical user interfaces (GUIs), you will often find that you need to create more than one window.
0 Comments
Leave a Reply. |