More "Demo Program Catchup" updates. Working through them bit by bit.....
This commit is contained in:
parent
1eb653d910
commit
f1e0c7d03f
|
@ -1,8 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import PySimpleGUI as sg
|
||||
print(sg.version, sg)
|
||||
|
||||
'''
|
||||
Usage of Column Element
|
||||
|
||||
How to embed a layout in a layout
|
||||
|
||||
Copyright 2022 PySimpleGUI
|
||||
'''
|
||||
|
||||
sg.theme('BlueMono')
|
||||
|
@ -14,12 +18,12 @@ col = [[sg.Text('col Row 1', text_color='white', background_color='blue')],
|
|||
# Window layout
|
||||
layout = [[sg.Listbox(values=('Listbox Item 1', 'Listbox Item 2', 'Listbox Item 3'),
|
||||
select_mode=sg.LISTBOX_SELECT_MODE_MULTIPLE, size=(20, 3)),
|
||||
sg.Col(col, background_color='blue')],
|
||||
sg.Column(col, background_color='blue')],
|
||||
[sg.Input('Last input')],
|
||||
[sg.OK()]]
|
||||
|
||||
# Display the window and get values
|
||||
window = sg.Window('Compact 1-line form with column', layout, margins=(0,0), element_padding=(0,0))
|
||||
window = sg.Window('Column Element', layout, margins=(0,0), element_padding=(0,0))
|
||||
event, values = window.read()
|
||||
|
||||
sg.popup(event, values, line_width=200)
|
||||
|
|
|
@ -24,6 +24,9 @@ def make_win2():
|
|||
[sg.Button('Erase'), sg.Button('Popup'), sg.Button('Exit')]]
|
||||
return sg.Window('Second Window', layout, finalize=True)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
window1, window2 = make_win1(), None # start off with 1 window open
|
||||
|
||||
while True: # Event Loop
|
||||
|
@ -44,3 +47,6 @@ while True: # Event Loop
|
|||
window['-OUTPUT-'].update('')
|
||||
window['-IN-'].update('')
|
||||
window.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,18 +1,22 @@
|
|||
import PySimpleGUI as sg
|
||||
|
||||
layout = [
|
||||
[sg.Text('Your typed chars appear here:'),
|
||||
sg.Text(size=(20, 1), key='-OUTPUT-')],
|
||||
[sg.Input('', key='-IN-')],
|
||||
[sg.Button('Show'), sg.Button('Exit')]
|
||||
]
|
||||
"""
|
||||
The basic PySimpleGUI design pattern for a persistent window that is
|
||||
updated using data input from one of the elements.
|
||||
|
||||
Copyright 2020 PySimpleGUI.org
|
||||
"""
|
||||
|
||||
layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(20, 1), key='-OUTPUT-')],
|
||||
[sg.Input(key='-IN-')],
|
||||
[sg.Button('Show'), sg.Button('Exit')]]
|
||||
|
||||
window = sg.Window('Window Title', layout)
|
||||
|
||||
while True:
|
||||
event, values = window.read()
|
||||
print(event, values)
|
||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||
if event == sg.WIN_CLOSED or event == 'Exit':
|
||||
break
|
||||
if event == 'Show':
|
||||
# change the "output" element to be the value of "input" element
|
||||
|
|
|
@ -2,8 +2,10 @@ import PySimpleGUI as sg
|
|||
|
||||
"""
|
||||
Simple field validation
|
||||
Input field should only accept digits.
|
||||
Input field should only accept digits 0-9.
|
||||
If non-digit entered, it is deleted from the field
|
||||
|
||||
Copyright 2022 PySimpleGUI
|
||||
"""
|
||||
|
||||
layout = [[sg.Text('Enter digits:')],
|
||||
|
@ -14,10 +16,11 @@ window = sg.Window('Window Title', layout)
|
|||
|
||||
while True: # Event Loop
|
||||
event, values = window.read()
|
||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||
print(event, values)
|
||||
if event == sg.WIN_CLOSED or event == 'Exit':
|
||||
break
|
||||
# if last char entered not a digit
|
||||
if len(values['-INPUT-']) and values['-INPUT-'][-1] not in ('0123456789'):
|
||||
if event == '-INPUT-' and len(values['-INPUT-']) and values['-INPUT-'][-1] not in ('0123456789'):
|
||||
# delete last char from input
|
||||
window['-INPUT-'].update(values['-INPUT-'][:-1])
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import cv2, PySimpleGUI as sg
|
||||
window, cap = sg.Window('Demo Application - OpenCV Integration', [[sg.Image(key='-IMAGE-')], ], location=(800, 400)), cv2.VideoCapture(0)
|
||||
# Make the window
|
||||
window, cap = sg.Window('Demo Application - OpenCV Integration', [[sg.Image(filename='', key='image')], ], location=(800, 400)), cv2.VideoCapture(0)
|
||||
# Loop reading video frames
|
||||
while window(timeout=20)[0] is not None:
|
||||
window['-IMAGE-'](data=cv2.imencode('.png', cap.read()[1])[1].tobytes())
|
||||
# Read a video frame and write it to the window
|
||||
window['image'](data=cv2.imencode('.png', cap.read()[1])[1].tobytes())
|
|
@ -1,14 +1,20 @@
|
|||
import cv2, PySimpleGUI as sg
|
||||
|
||||
window = sg.Window('Demo Application - OpenCV Integration', [[sg.Image(filename='', key='image')], ], location=(800, 400))
|
||||
window = sg.Window('Demo Application - OpenCV Integration', [[sg.Image(key='-I-')], ], location=(800, 400))
|
||||
cap = cv2.VideoCapture(0) # Setup the camera as a capture device
|
||||
while True: # The PSG "Event Loop"
|
||||
event, values = window.read(timeout=20, timeout_key='timeout') # get events for the window with 20ms max wait
|
||||
event, values = window.read(timeout=20) # get events for the window with 20ms max wait
|
||||
if event == sg.WIN_CLOSED: break # if user closed window, quit
|
||||
window['image'].update(data=cv2.imencode('.png', cap.read()[1])[1].tobytes()) # Update image in window
|
||||
window['-I-'].update(data=cv2.imencode('.ppm', cap.read()[1])[1].tobytes()) # Update image in window
|
||||
|
||||
"""
|
||||
Putting the comment at the bottom so that you can see that the code is indeed 7 lines long. And, there is nothing
|
||||
done out of the ordinary to make it 7 lines long. There are no ; for example. OK, so the if statement is on one line
|
||||
but that's the only place that you would traditionally see one more line. So, call it 8 if you want.
|
||||
|
||||
NOTE - the encoding format PPM has been shown to be significantly less CPU intensive than using PNG (thank you reporting PySimpleGUI user!)
|
||||
|
||||
In some cases however, PPM may not be supported. If you have problems with PPM encoding, then change ".ppm" to ".png" on line 8.
|
||||
|
||||
Copyright 2022 PySimpleGUI
|
||||
"""
|
|
@ -13,7 +13,7 @@ import PySimpleGUI as sg
|
|||
|
||||
sg.theme('DarkBlue')
|
||||
|
||||
layout = [[sg.Text('', size=(50, 1), relief='sunken', font=('Courier', 11),
|
||||
layout = [[sg.Text('', size=(50, 1), relief='sunken',
|
||||
text_color='yellow', background_color='black',key='-TEXT-', metadata=0)]]
|
||||
|
||||
window = sg.Window('Title', layout, finalize=True)
|
||||
|
@ -27,6 +27,6 @@ while True:
|
|||
if event == sg.WINDOW_CLOSED:
|
||||
break
|
||||
text.metadata = (text.metadata + 1) % 51
|
||||
text.update('█' * text.metadata)
|
||||
text.update(sg.SYMBOL_SQUARE * text.metadata)
|
||||
|
||||
window.close()
|
|
@ -10,9 +10,4 @@ import PySimpleGUI as sg
|
|||
Copyright 2021 PySimpleGUI
|
||||
"""
|
||||
|
||||
sg.Window('Sudoku', [[sg.Frame('', [[sg.Input(justification='r', size=(3,1))
|
||||
for col in range(3)]
|
||||
for row in range(3)])
|
||||
for frame_col in range(3)]
|
||||
for frame_row in range(3)],
|
||||
use_custom_titlebar=True).read()
|
||||
sg.Window('Sudoku', [[sg.Frame('', [[sg.Input(justification='r', size=(3,1)) for col in range(3)] for row in range(3)]) for frame_col in range(3)] for frame_row in range(3)], use_custom_titlebar=True).read()
|
||||
|
|
|
@ -1,29 +1,38 @@
|
|||
# import PySimpleGUI as sg
|
||||
import PySimpleGUIWx as sg
|
||||
import PySimpleGUI as sg
|
||||
# import PySimpleGUIWx as sg
|
||||
# import PySimpleGUIQt as sg
|
||||
|
||||
|
||||
"""
|
||||
System Tray Icon
|
||||
Your very own personsal status monitor in your system tray
|
||||
Your very own peronsal status monitor in your system tray
|
||||
Super easy to use.
|
||||
1. Find an icon file or use this default
|
||||
2. Create your menu definition
|
||||
2. Create your menu defintion
|
||||
3. Add if statements to take action based on your input
|
||||
|
||||
Note from the imports that this code works on all PySimpleGUI ports (except Web).
|
||||
For the tkinter port, however, the icon isn't located in the system tray. Instead it's located just above
|
||||
the system tray in the form of what looks like an "icon" on your desktop. It's actually a very small window.
|
||||
|
||||
In June 2021 a new package was added to the PySimpleGUI family - psgtray
|
||||
With this package, you can get a real system tray icon while using tkinter rather than a desktop-icon that this
|
||||
demo is demonstrating. The Demo Program - Demo_psgtray_Tray_Icon_Tkinter - shows how to integrate it with PySimpleGUI
|
||||
|
||||
Copyright 2022 PySimpleGUI
|
||||
"""
|
||||
|
||||
|
||||
menu_def = ['UNUSED', ['My', 'Simple', '---', 'Menu', 'Exit']]
|
||||
|
||||
|
||||
menu_def = ['UNUSED', ['My', '&Simple::my key', 'Has Sub', ['1','2'], '---', 'Menu', 'E&xit']]
|
||||
|
||||
tray = sg.SystemTray(menu=menu_def, data_base64=sg.DEFAULT_BASE64_ICON)
|
||||
|
||||
while True:
|
||||
event = tray.read()
|
||||
print(event)
|
||||
if event == 'Exit':
|
||||
break
|
||||
elif event == 'Menu':
|
||||
tray.show_message('Title', 'Hey, you clicked Menu!')
|
||||
tray.close()
|
Loading…
Reference in New Issue