Restored cookbook from a backup

This commit is contained in:
MikeTheWatchGuy 2019-03-18 13:30:32 -04:00
parent 49879a9bbd
commit 9ff65d3ede
1 changed files with 37 additions and 6 deletions

View File

@ -20,6 +20,12 @@ There is a short section in the Readme with instruction on installing PySimpleGU
If you like this Cookbook, then you'll LOVE the 100+ sample programs that are just like these. You'll find them in the GitHub at http://www.PySimpleGUI.com. These Recipes are simply several of those programs displayed in document format. If you like this Cookbook, then you'll LOVE the 100+ sample programs that are just like these. You'll find them in the GitHub at http://www.PySimpleGUI.com. These Recipes are simply several of those programs displayed in document format.
# Experimental repl.it Embedded Windows
You'll find a few of these Recipes are running in your browser window using PySimpleGUIWeb. They are included so that you can immediately play around with the SDK before installing one of the PySimpleGUI variants on your computer.
This is a new capability for PySimpleGUI that has only very recently been started. Only a few of the elements are operational using PySimpleGUIWeb. So, be prepared for some bugs. It's got a ways to go, but still seemed valuable to include.
# Copy these design patterns! # Copy these design patterns!
All of your PySimpleGUI programs will utilize one of these 2 design patterns depending on the type of window you're implementing. The two types of windows are: All of your PySimpleGUI programs will utilize one of these 2 design patterns depending on the type of window you're implementing. The two types of windows are:
@ -41,7 +47,7 @@ This will be the most common pattern you'll follow if you are not using an "even
import PySimpleGUI as sg import PySimpleGUI as sg
layout = [[sg.Text('My one-shot window.')], layout = [[sg.Text('My one-shot window.')],
[sg.InputText(), sg.FileBrowse()], [sg.InputText()],
[sg.Submit(), sg.Cancel()]] [sg.Submit(), sg.Cancel()]]
window = sg.Window('Window Title').Layout(layout) window = sg.Window('Window Title').Layout(layout)
@ -49,9 +55,12 @@ window = sg.Window('Window Title').Layout(layout)
event, values = window.Read() event, values = window.Read()
window.Close() window.Close()
source_filename = values[0] text_input = values[0]
print(text_input)
``` ```
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Design-Pattern-1-One-shot-Window?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
## Pattern 2 A - Persistent window (multiple reads using an event loop) ## Pattern 2 A - Persistent window (multiple reads using an event loop)
@ -79,6 +88,10 @@ while True:
window.Close() window.Close()
``` ```
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Design-Pattern-2A-Persistent-Window?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
## Pattern 2 B - Persistent window (multiple reads using an event loop + updates data in window) ## Pattern 2 B - Persistent window (multiple reads using an event loop + updates data in window)
This is a slightly more complex, but maybe more realistic version that reads input from the user and displays that input as text in the window. Your program is likely to be doing both of those activities so this will give you a big jump-start. This is a slightly more complex, but maybe more realistic version that reads input from the user and displays that input as text in the window. Your program is likely to be doing both of those activities so this will give you a big jump-start.
@ -112,7 +125,7 @@ while True: # Event Loop
window.Close() window.Close()
``` ```
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Design-Pattern-2B-Persistent-Window-with-Updates?lite=false" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
# Simple Data Entry - Return Values As List # Simple Data Entry - Return Values As List
@ -139,6 +152,8 @@ Same GUI screen except the return values are in a list instead of a dictionary a
print(event, values[0], values[1], values[2]) print(event, values[0], values[1], values[2])
``` ```
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Cookbook-Return-Values-as-List?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
# Simple data entry - Return Values As Dictionary # Simple data entry - Return Values As Dictionary
A simple GUI with default values. Results returned in a dictionary. A simple GUI with default values. Results returned in a dictionary.
@ -165,7 +180,11 @@ A simple GUI with default values. Results returned in a dictionary.
print(event, values['_NAME_'], values['_ADDRESS_'], values['_PHONE_']) print(event, values['_NAME_'], values['_ADDRESS_'], values['_PHONE_'])
``` ```
---------------------
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Cookbook-Return-Values-As-Dictionary?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
-------
@ -327,6 +346,7 @@ while True:
window.FindElement('_OUTPUT_').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100)) window.FindElement('_OUTPUT_').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
``` ```
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Cookbook-Timer?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
-------- --------
@ -775,6 +795,8 @@ while True: # Event Loop
window.Close() window.Close()
``` ```
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Cookbook-Compound-Element?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
## Multiple Windows ## Multiple Windows
This recipe is a design pattern for multiple windows where the first window is not active while the second window is showing. The first window is hidden to discourage continued interaction. This recipe is a design pattern for multiple windows where the first window is not active while the second window is showing. The first window is hidden to discourage continued interaction.
@ -950,6 +972,9 @@ There are a number of features used in this Recipe including:
window.FindElement('input').Update(keys_entered) # change the window to reflect current key string window.FindElement('input').Update(keys_entered) # change the window to reflect current key string
``` ```
<iframe height="800px" width="100%" src="https://repl.it/@PySimpleGUI/Cookbook-Keypad-Touchscreen-Entry?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>
## Animated Matplotlib Graph ## Animated Matplotlib Graph
Use the Canvas Element to create an animated graph. The code is a bit tricky to follow, but if you know Matplotlib then this recipe shouldn't be too difficult to copy and modify. Use the Canvas Element to create an animated graph. The code is a bit tricky to follow, but if you know Matplotlib then this recipe shouldn't be too difficult to copy and modify.
@ -1525,3 +1550,9 @@ That's all... Run your `my_program.exe` file on the Windows machine of your choo
(famous last words that screw up just about anything being referenced) (famous last words that screw up just about anything being referenced)
Your EXE file should run without creating a "shell window". Only the GUI window should show up on your taskbar. Your EXE file should run without creating a "shell window". Only the GUI window should show up on your taskbar.
<!--stackedit_data:
eyJoaXN0b3J5IjpbLTEzNTc5NjUyNTUsLTk0Mjc2ODgzNywtMz
UwNzA2ODE4LC0xOTgzMjAzNjMwLC0xMDAwMjc2OTU0LC0xNDAy
ODQwOTg2LDY2ODc4OTc0OSwtMTE3NDc5OTg5Miw3MTcwNDk2Nj
AsLTY3OTU0OTY3NSwtMzM5MzcxMzUyXX0=
-->