ecookbook restoring the folders for testing...
This commit is contained in:
parent
0574702876
commit
9f40a47d30
109 changed files with 0 additions and 0 deletions
40
docs/eCookbook/demo-programs/all-elements-simple-view.md
Normal file
40
docs/eCookbook/demo-programs/all-elements-simple-view.md
Normal file
|
@ -0,0 +1,40 @@
|
|||
## All Elements - Listed in 1 Window
|
||||
|
||||
This program is a slightly modified version of the Demo Program found in the PySimpleGUI repo:
|
||||
|
||||
`Demo_All_Elements_Simple.py`
|
||||
|
||||
|
||||
The view of this window here on Trinket looks a little different than the code when run on Windows
|
||||
|
||||
### Trinket
|
||||
|
||||

|
||||
|
||||
|
||||
### Windows 10
|
||||
|
||||

|
||||
|
||||
### Titlebar and Menubar
|
||||
|
||||
The thing I want to draw your attention to is the Titlebar and the Menubar.
|
||||
|
||||
Because Trinket does not provide a Titlebar (it's the operating system's job to do this), PySimpleGUI provides one for you automatically. PySimpleGUI doesn't automatically switch your Menubar to a MenubarCustom which is what you need to use on Trinket for the 2 to match. The code in this Trinket has been modified to add the custom Menubar for you.
|
||||
|
||||
|
||||
### The code
|
||||
|
||||
This demo was written to show you the "pallet of elements" that you have available to paint your GUI window with. It doesn't tell the full story however as you can expand these GREATLY by using PIL, the graph element, images for buttons, etc. What it does do is list all of the elements using 1 line of code per element. It can't get much simpler than that.
|
||||
|
||||
|
||||
### Theme Previewer
|
||||
|
||||
This proram has a secondary function... you can see what all of the elements look like using the many PySimpleGUI Themes. Choose a new theme from the Combo element shown and the window will be remade with the new theme.
|
||||
|
||||
For example, I chose the "Dark Grey 11" theme and was shown this window:
|
||||
|
||||

|
||||
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/f72e2992d2?start=result' width='100%' height='700' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
|
@ -0,0 +1,14 @@
|
|||
Simple Chat program front end
|
||||
|
||||
This demo was kept short and simple as to provide a foundation for something more elaborate (or not). Didn't want to make it so that you have to remove more code than you add.
|
||||
|
||||
This program takes input from the user and uses print statements to output information to the window.
|
||||
|
||||
A couple of features may not be what you're looking for and are easy to change are:
|
||||
* Enter key "sends" the message
|
||||
* After every send the input element is cleared
|
||||
|
||||
This chat program is synchronous in its design. It gathers input, "sends" it or processes it in some manner and then outputs the results. If you need is more asynchronous, then you'll want to use a PySimpleGUI async design pattern instead of this more simple synchronous one.
|
||||
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/7b058a66bc?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
13
docs/eCookbook/demo-programs/control-panel.md
Normal file
13
docs/eCookbook/demo-programs/control-panel.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
**Control Panel**
|
||||
|
||||
Creates a grid of images with text labels that looks like a typical "control panel".
|
||||
|
||||
Note that there is currently a bug with the `Column` Element where the mousewheel only scrolls the Column if mouse is directrly over the scrollwheel.
|
||||
|
||||
This code contains a lot of Base64 Images in order to avoid needing to distributes a lot of individual image files with the code. This way a single source file has everything required.
|
||||
|
||||
On Windows the window looks like this:
|
||||
|
||||

|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/d12422e22c?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
|
@ -0,0 +1,32 @@
|
|||
**Design Pattern 1 - The One-Shot
|
||||
**
|
||||
Use this design pattern to show a window, get some input values and then close the window. The window is not meant to stick around for very long.
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/87c8b8cdd6?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
||||
|
||||
|
||||
An exciting development in 2019 was the addition of the `close` parameter to the `window.read()` call. This enables you to write single line GUIs (again), a capability that was around in the early days of PySimpleGUI but disappeared as persistent windows became the primary use.
|
||||
|
||||
To make a single line, one-shot-GUI, you combine the layout into the call to `Window` itself. You also "chain" the call to read onto the end of your `Window` call.
|
||||
|
||||
The result is a line that looks like this:
|
||||
```python
|
||||
event, values = sg.Window('My single-line GUI!',
|
||||
[[sg.Text('My one-shot window.')],
|
||||
[sg.InputText(key='-IN-')],
|
||||
[sg.Submit(), sg.Cancel()]]).read(close=True)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/d4c897136b?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
||||
|
||||
|
||||
You can take this approach one step further and parse out the input value directly into your variable by adding more code onto the end of the line. In this case, a subscript to pick up the second location in the tuple that's returned from `read` and then the key.
|
||||
|
||||
```python
|
||||
event, values = sg.Window('My single-line GUI!',
|
||||
[[sg.Text('My one-shot window.')],
|
||||
[sg.InputText(key='-IN-')],
|
||||
[sg.Submit(), sg.Cancel()]]).read(close=True)[1]['-IN-']
|
||||
```
|
|
@ -0,0 +1,20 @@
|
|||
**Design Pattern 2 - Persistent Windows, output updates in window**
|
||||
|
||||
|
||||
***This is the most common design pattern you'll find in PySimpleGUI. ***
|
||||
|
||||
It's the same across all of the ports of PySimpleGUI. You'll easily be able to recognize a PySimpleGUI program by this basic structure.
|
||||
|
||||
This pattern is for windows that remain open with the user interacting with them. It's a "normal" window from a user's standpoint.
|
||||
|
||||
*This pattern has 4 parts:*
|
||||
|
||||
1. Layout definition
|
||||
2. Window creation
|
||||
3. Event loop - read window events and inputs
|
||||
4. Window close
|
||||
|
||||
Each of these parts is 1 or 2 lines of Python code when working with a basic window. The size of the event loop depends on the amount of processing you need to do when events happen in the window.
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/c0bf3a6754?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
||||
|
51
docs/eCookbook/demo-programs/informe-os-dados.md
Normal file
51
docs/eCookbook/demo-programs/informe-os-dados.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
|
||||
It's sometimes useful to exlore what it would take to duplicate a GUI written in tkinter, especially when a nicely written article accompanies the code.
|
||||
|
||||
This GUI code duplicates a portion of the tkinter code posted on this page:
|
||||
https://www.devmedia.com.br/tkinter-interfaces-graficas-em-python/33956
|
||||
|
||||
It performs performs the logic for only the "Inserir" button.
|
||||
|
||||
To add the code for the remaining buttons, add `elif` statements onto the bottom of the `if` statement in the event loop. At the moment, buttons that are not handled in the event loop causes a "Not yet implemlented" message to be shown.
|
||||
|
||||
On a Windows machine, the window this code produces looks like this:
|
||||
|
||||

|
||||
|
||||
|
||||
PySimpleGUI is a package that provides an interface to GUI Frameworks that uses constructs familiar to Python programmers of all experience levels. With PySimpleGUI you can run your source code on tkinter, Qt, WxPython and in a browser... on Windows, Mac and Linux
|
||||
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/c50932b36f?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
||||
|
||||
One of the "neat tricks" that PySimpleGUI has is the ability to run on multiple GUI platforms with a minimal amount of changes to your code. Often it is just 1 line of code to change.
|
||||
|
||||
You can't do this on Trinket, in your browser because Trinket only supports tkinter.
|
||||
|
||||
For the example code above, running on a Windows machine, the import statement at the top was changed to use a version of PySimpleGUI that runs on Qt, WxPython and in the browser (using Remi). Note that the windows produced are not perfect and may need a font size or other change to make it look better, but the several character change using PySimpleGUI is tiny compared to what it would take to port tkinter code to Qt.
|
||||
|
||||
Changed the import to run on PySide2 (Qt)
|
||||
```python
|
||||
import PySimpleGUIQt as sg
|
||||
```
|
||||
|
||||
The code then created this window running on Qt
|
||||
|
||||

|
||||
|
||||
Changed the import to run on WxPython
|
||||
```python
|
||||
import PySimpleGUIWx as sg
|
||||
```
|
||||
|
||||
The code then created this window running on WxPython
|
||||

|
||||
|
||||
Changed the import to run in a browser:
|
||||
```python
|
||||
import PySimpleGUIWeb as sg
|
||||
```
|
||||
|
||||
The code then created this window running in a chrome window
|
||||
|
||||

|
65
docs/eCookbook/demo-programs/intro-to-this-page.md
Normal file
65
docs/eCookbook/demo-programs/intro-to-this-page.md
Normal file
|
@ -0,0 +1,65 @@
|
|||

|
||||
# Welcome to the PySimpleGUI Interactive eCookbook
|
||||
|
||||
SOME of these Trinkets are older, but all work.
|
||||
|
||||
Use the navigation bar on the left to look through the pages. Each page has ***at least*** one demo program for you to RUN in your browser.
|
||||
|
||||
With this eCookbook you don't need to do anything than **click run**. That's it. You can see the code that's running, modify it, and if you find it particulrly useful, copy it to your machine and use it in your project.
|
||||
|
||||
## Example - The Basic PySimpleGUI Program
|
||||
|
||||
Let's start with the most basic of PySimpleGUI programs so you know how they work.
|
||||
|
||||
The code is on the left. Clicking run will show the GUI on the right side. The print output (stdout, stderr) are down in a window below the GUI. There are more controls, but that's enough to get you running. So, go ahead, **click RUN!**
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/36bf0df5f3?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
||||
|
||||
|
||||
|
||||
## The Regular (other) Cookbook
|
||||
|
||||
You'll find the full PySimpleGUI Cookbook where it's always been located, on ReadTheDocs as a tab in the user documentation.
|
||||
|
||||
http://Cookbook.PySimpleGUI.org
|
||||
|
||||
## The Demo Programs
|
||||
|
||||
There are over 300 .py .pyw files on the PySimpleGUI Repo that you can consider to be Cookbook Recipes. They show you how PySimpleGUI works and how to integrate PySimpleGUI with other packages. Ready to run bookbook recipes that are simple enough and commented enough that you don't need text.
|
||||
|
||||
http://Demos.PySimpleGUI.org
|
||||
|
||||
## The Full Documenation
|
||||
|
||||
The Cookbook, primary doc, readme, call reference, etc, can always be found here:
|
||||
|
||||
http://www.PySimpleGUI.org
|
||||
|
||||
|
||||
## Known (slight) Problems
|
||||
|
||||
### Missing Titlebars
|
||||
|
||||
Special code was added to PySimpleGUI to use a custom Titlebar when the program is running on Trinket. Not all Trinkets have this code added to them.
|
||||
|
||||
You will notice with older versions of PySimpleGUI and Trinket that there is no titlebar on the window. That is because the titlebar is provided by the Operating System and Trinket doesn't really have one and thus the need for PySimpleGUI's custom code.
|
||||
|
||||
### Smaller Screen Real Estate
|
||||
|
||||
800 x 600 is the size of a standard Trinket screen that PySimpleGUI has to work with.
|
||||
|
||||
That's quite small when you're trying to run Demo Programs from the PySimpleGUI project. Some won't fit. Most will though.
|
||||
|
||||
You may need to use the full-screen mode for some examples. Information about full-screen is on this page in one of the first examples.
|
||||
|
||||
## Consider Supporting Trinket
|
||||
|
||||
Trinket is a **fantastic** platform for teaching PySimpleGUI. It's easy for students to use. It's easy for teachers to use. It doesn't require anyone to install anything anywhere. All that's needed is a browser. Coding from a tablet is difficult unless you have a keyboard, that's true for every coding site on the internet.
|
||||
|
||||
I consider Trinket to be a partner. They've provided solid service to the PySimpleGUI community for several years. "It just works" is one of the most valuable traits for a product or service and PySimpleGUI "just works" on Trinket. Make a new PyGrame Trinket project, type `import PySimpleGUI as sg`, and you're ready to start having fun!
|
||||
|
||||
The prices are riduculously low what we're all getting to experience - PySimpleGUI running in the browser with zero effort on your part.
|
||||
|
||||
## Get on with learning!
|
||||
|
||||
Start clicking topics on the left table of contents and have fun while learning PySimpleGUI.....
|
15
docs/eCookbook/demo-programs/menu-bar.md
Normal file
15
docs/eCookbook/demo-programs/menu-bar.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
```python.run
|
||||
runnable code goes here
|
||||
```## Collapsible Sections
|
||||
|
||||
Visible / Invisible settings on the plain tkinter based PySimpleGUI have been a real challenge. In release 4.28.0 a new function, `pin`, was added that will "pin" an element to a location in your layout. This will reserve the location for the element in the layout. Without it, the element will move when you make it inivisible and visible again.
|
||||
|
||||
There is a 1-pixel "penalty" of sorts when using this capability. A single pixel is needed to reserve and hold this spot, a small price to pay given what you can do with this new capability.
|
||||
|
||||
This demo shows how you can use this feature to make Column elements invisible as if a section of the window has been collapsed with the contents hidden.
|
||||
|
||||
Here is how the demo looks running on Windows
|
||||
|
||||

|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/df2c15979e?start=result' width='100%' height='600' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
24
docs/eCookbook/demo-programs/menus.md
Normal file
24
docs/eCookbook/demo-programs/menus.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
## Menubar and Titlebar With Trinkets
|
||||
|
||||
## Menus - MenubarCustom instead of Menu
|
||||
|
||||
There's a tricky issue with Trinket. Trinket doesn't supply a titlebar by default. You may notice that many of the older examples here lack a titlebar. That's because it's only been in 2021 that a custom titlebar was developed and automatically added when the runtime enironment is Trinket.
|
||||
|
||||
There's one issue with these Custom Titlebars.... you need a custom Menubar to go with them. -sigh-
|
||||
|
||||
You'll find MenubarCustom is an element that works much like a normal Menu element.
|
||||
|
||||
## Info from original Trinket made in 2019, but code updated in 2021:
|
||||
|
||||
This demo shows you how you can add a menu bar to your program.
|
||||
You will receive events that are the menu item's text or the menu
|
||||
item's key.
|
||||
|
||||
The main purpose of this demo is to teach you the layout of a menu definition.
|
||||
It is a basic Python list with listings inside that respresent the cascading
|
||||
of menus. You can go as deep as you with.
|
||||
|
||||
Notice that the `ButtonMenu` Element is a little different. The MenuBar and right click menus both return the menu item chosen as the event. For the `ButtonMenu` Element the key of the button is returned. The menu item chosen is in the values variable. It's a 2-step process to get the menu item chosen for `ButtonMenu` elements.
|
||||
|
||||
|
||||
<iframe src="https://trinket.io/embed/pygame/b96cfa2f55" width="100%" height="600" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>
|
29
docs/eCookbook/demo-programs/multi-threaded-work.md
Normal file
29
docs/eCookbook/demo-programs/multi-threaded-work.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
**Multi-Threaded Work - Running long tasks inside of a GUI**
|
||||
|
||||
This program demonstrates one way of using a combination of Python's Thread
|
||||
and Queue objects to implement a GUI that performs work that takes too long
|
||||
to directly perform inside of the event loop.
|
||||
|
||||
An example use would be if you have a button that you want to use to start
|
||||
some code that will take several seconds to run, then this technique is a
|
||||
good pattern to use.
|
||||
|
||||
Take a moment to examine the code dealing with the Thread and the Queue. These
|
||||
constructs are nothing to fear as the amount of code that uses them is only a
|
||||
handul of lines of code are needed. And they are simple enough that you'll
|
||||
be able to understand them.
|
||||
|
||||
***"Thread-safe"*** - This is an important term to consider any time you are using threads in your program. There are 2 things to check out:
|
||||
1. You must make sure that the calls you make from your thread are OK to call from a thread
|
||||
2. If you are running multiple threads, then the calls you make must be "thread-safe"
|
||||
|
||||
The authors of libraries you are using often tell you if their code is "thread-safe".
|
||||
|
||||
PySimpleGUI code is not thread safe. For the tkinter version (i.e. plain PySimpleGUI versus PySimpleGUIQt), you cannot run PySimpleGUI as a thread. To put that in simpler terms, you cannot make any calls into the PySimpleGUI package from a thread. For example, you cannot call `update` for any of your elements from a thread. This is why you see the updates happening from the main thread only.
|
||||
|
||||
Screenshot:
|
||||
|
||||

|
||||
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/8f2aeea67b?start=result' width='100%' height='650' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
|
@ -0,0 +1,22 @@
|
|||
# Demo Programs
|
||||
|
||||
The [Demo Progams](http://Demos.PySimpleGUI.org) were the basis for many of the Trinkets you see on this page. There are over 300 of them to help give you a fast jump start on building your application, or they will teach you how to perform various operations.
|
||||
|
||||
If you want to learn how an element works, see example code, then check out the Demo Programs.
|
||||
|
||||
In 2022 a new PySimpleGUI application, `psgdemos`, was released to [PyPI](https://pypi.org/project/psgdemos/). All you need to do is:
|
||||
|
||||
`python -m pip install psgdemos`
|
||||
`psgdemos`
|
||||
|
||||
(Use `python3` if you're on Linux or Mac)
|
||||
|
||||
The command `psgdemos` will launch the Demo Browser, your gateway to Demo Program fun. The Demo Browser enables you to easily **search**, **run**, and **edit** the programs.
|
||||
|
||||
For example, if you want to learn more about using the `Graph` element, then use the Demo Browser to search for Demo Programs that use that element:
|
||||
|
||||

|
||||
|
||||
You can learn more about the Demo Browser and installing Demo Programs in the Cookbook, in the [Recipe on Demo Browser](https://pysimplegui.readthedocs.io/en/latest/cookbook/#recipe-the-demo-browser)
|
||||
|
||||
It's by far the easiest way to navigate the many examples available for you use.
|
22
docs/eCookbook/demo-programs/settings-file.md
Normal file
22
docs/eCookbook/demo-programs/settings-file.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
### Settings File - Load & Save Programming Settings
|
||||
|
||||
This demo program shows one way to save your program's settings using a JSON file as your settings file. This code is particularly handy when you are building desktop-widgets like a Rainmater type of desktop widget.
|
||||
|
||||
The main program in the example is very small. The focus is on the settings window.
|
||||
|
||||

|
||||
|
||||
This is the settings window.
|
||||
|
||||

|
||||
|
||||
Now you can easily add settings to your programs that are saved to disk, a very nice touch that adds a lot of polish to your programs.
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/2d7e078757?start=result' width='100%' height='600' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
||||
|
||||
### Config.ini format
|
||||
|
||||
In version 4.49.0.10 support for .INI format files was added. This is a quick example of how to use INI files with PySimpleGUI's User Settings APIs
|
||||
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/9de8c06992?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
12
docs/eCookbook/demo-programs/simple-form.md
Normal file
12
docs/eCookbook/demo-programs/simple-form.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
Menu Bar
|
||||
|
||||
There are 4 places you'll run into menus in PySimpleGUI
|
||||
1. Menu Bar
|
||||
2. Right Click Menu
|
||||
3. Button Menu
|
||||
4. System Tray
|
||||
|
||||
This demo showns how the Menu Bar element works and the format for the Menu Bar menus.
|
||||
|
||||
|
||||
<iframe src='https://trinket.io/embed/pygame/cbd8d14a70?start=result' width='100%' height='500' frameborder='0' marginwidth='0' marginheight='0' allowfullscreen></iframe>
|
|
@ -0,0 +1,49 @@
|
|||
**Basic PySimpleGUI Program**
|
||||
|
||||
* The basic PySimpleGUI 3 part program structure
|
||||
* Enlarging windows on Trinket
|
||||
* Running PySimpleGUI on the repl.it site
|
||||
|
||||
------
|
||||
|
||||
The basic PySimpleGUI program, in 3 parts.
|
||||
|
||||
Almost all PySimpleGUI programs have this architecture.
|
||||
|
||||
First you define the window.
|
||||
Then create the window.
|
||||
Finally you collect inputs and operate on 'events'
|
||||
|
||||
This is a good one to copy as a template
|
||||
|
||||
<iframe src="https://trinket.io/embed/pygame/36bf0df5f3" width="100%" height="500" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>
|
||||
|
||||
-----
|
||||
|
||||
**Enlarging windows on Trinket**
|
||||
|
||||
Sometimes when you're running these Trinket examples, the window is so small that it's difficult to make out the text. To view the examples in much larger sizes, choose "Fullscreen" from the menu.
|
||||
|
||||

|
||||
|
||||
|
||||
This will make your window go from this:
|
||||
|
||||

|
||||
|
||||
to this:
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
----
|
||||
|
||||
**Running code on repl.it**
|
||||
|
||||
In addition to being able to run PySimpleGUI code online here on Trinket, you can also run PySimpleGUI on repl.it. The advantage to running on repl.it is that you have the ability to pip install nearly anything. Trinket severly limits what you can install and in fact with each of these examples the entire PySimpleGUI source code is being included. On repl.it the PySimpleGUI package is installed automatically for you.
|
||||
|
||||
Trinket seems to block embedding iframes to other sites. This link will display the above program on repl.it.
|
||||
|
||||
https://repl.it/@PySimpleGUI/Basic-PySimpleGUI-Template
|
||||
|
12
docs/eCookbook/demo-programs/ti-datamath-ii-calculator.md
Normal file
12
docs/eCookbook/demo-programs/ti-datamath-ii-calculator.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
All credit for this code, the video and hard work belongs to Israel Dryer. His GitHub repository is located here: https://github.com/israel-dryer
|
||||
|
||||
This calculator was developed as part of a YouTube tutorial. You can watch the video that describes how to make this calculator here:
|
||||
|
||||
https://youtu.be/x5LSTDdffFk
|
||||
|
||||
The GitHub location for the source can be found here:
|
||||
|
||||
https://github.com/israel-dryer/PyDataMath-II
|
||||
|
||||
|
||||
<iframe src="https://trinket.io/embed/pygame/e51fa16b0b" width="100%" height="600" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>
|
Loading…
Add table
Add a link
Reference in a new issue