Cleaning up demos so local changes get rolled in. Old demos removed. There is a significant effort underway

This commit is contained in:
PySimpleGUI 2021-03-01 06:59:36 -05:00
parent 724d6ae7a9
commit 0ec79ce4b4
8 changed files with 35 additions and 64 deletions

View File

@ -30,11 +30,11 @@ gifs = [ring_blue, red_dots_ring, ring_black_dots, ring_gray_segments, ring_line
# first show how to use popup_animated using built-in GIF image # first show how to use popup_animated using built-in GIF image
for i in range(100000): for i in range(100000):
sg.popup_animated(sg.DEFAULT_BASE64_LOADING_GIF, no_titlebar=False, background_color='white', time_between_frames=100) sg.popup_animated(sg.DEFAULT_BASE64_LOADING_GIF, message='Right Click To Exit GIF Windows That Follow\nLeft click to move to next one', no_titlebar=False, time_between_frames=100, text_color='black', background_color='white')
sg.popup_animated(None) # close all Animated Popups sg.popup_animated(None) # close all Animated Popups
# Next demo is to show how to create custom windows with animations # Next demo is to show how to create custom windows with animations
layout = [[sg.Image(data=gifs[0], enable_events=True, background_color='white', key='-IMAGE-', right_click_menu=['UNUSED', 'Exit'])],] layout = [[sg.Image(data=gifs[0], enable_events=True, background_color='white', key='-IMAGE-', right_click_menu=['UNUSED', ['Exit']])],]
window = sg.Window('My new window', layout, window = sg.Window('My new window', layout,
no_titlebar=True, no_titlebar=True,
@ -53,7 +53,9 @@ while True: # Event Loop
break break
elif event == '-IMAGE-': # if clicked on the image elif event == '-IMAGE-': # if clicked on the image
if offset == len(gifs)-1:
break
offset += (offset < len(gifs)-1) # add 1 until the last one offset += (offset < len(gifs)-1) # add 1 until the last one
gif = gifs[offset] # get a new gif image gif = gifs[offset] # get a new gif image
# update the animation in the window # update the animation in the window
window['-IMAGE-'].update_animation(gif, time_between_frames=100) window['-IMAGE-'].update_animation(gif, time_between_frames=100)

View File

@ -14,19 +14,20 @@ import PySimpleGUI as sg
Copyright 2020 PySimpleGUI.org Copyright 2020 PySimpleGUI.org
""" """
gif_filename = r'my_gif_file.gif' gif_filename = r'ExampleGIF.gif'
layout = [[sg.Image(key='-IMAGE-')]] layout = [[sg.Text('Happy Thursday!', background_color='#A37A3B', text_color='#FFF000', justification='c', key='-T-', font=("Bodoni MT", 40))],
[sg.Image(key='-IMAGE-')]]
window = sg.Window('Window Title', layout, element_justification='c', margins=(0,0), element_padding=(0,0), finalize=True) window = sg.Window('Window Title', layout, element_justification='c', margins=(0,0), element_padding=(0,0), finalize=True)
sequence = [ImageTk.PhotoImage(img) for img in ImageSequence.Iterator(Image.open(gif_filename))] # must has finalized to do this window['-T-'].expand(True, True, True) # Make the Text element expand to take up all available space
interframe_duration = Image.open(gif_filename).info['duration'] # get how long to delay between frames interframe_duration = Image.open(gif_filename).info['duration'] # get how long to delay between frames
while True: while True:
for frame in sequence: for frame in ImageSequence.Iterator(Image.open(gif_filename)):
event, values = window.read(timeout=interframe_duration) event, values = window.read(timeout=interframe_duration)
if event == sg.WIN_CLOSED: if event == sg.WIN_CLOSED:
exit() exit(0)
window['-IMAGE-'].update(data=frame) window['-IMAGE-'].update(data=ImageTk.PhotoImage(frame) )

View File

@ -2,7 +2,7 @@ import PySimpleGUI as sg
import random import random
# Bars drawing in PySimpleGUI # Bars drawing in PySimpleGUI
# #
# .--. # .--.
# | | # | |
# .--.| |.--. # .--.| |.--.
@ -46,4 +46,4 @@ while True:
graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value), graph.draw_rectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue') bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue')
graph.draw_text(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10)) graph.draw_text(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
window.close() window.close()

File diff suppressed because one or more lines are too long

View File

@ -38,6 +38,7 @@ class BtnInfo:
# Main function that creates the layout, window and has event loop # Main function that creates the layout, window and has event loop
def main(): def main():
layout = [[sg.Text('Toggle Button')], layout = [[sg.Text('Toggle Button')],
[sg.T('Disabled with PySimpleGUI Ignore:', text_color='yellow')],
[sg.Button(image_data=on_image, k='-TOGGLE1-', border_width=0, [sg.Button(image_data=on_image, k='-TOGGLE1-', border_width=0,
button_color=(sg.theme_background_color(), sg.theme_background_color()), button_color=(sg.theme_background_color(), sg.theme_background_color()),
disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()), disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()),
@ -46,12 +47,23 @@ def main():
sg.Button(image_data=off_image, k='-DISABLE1-', border_width=0, sg.Button(image_data=off_image, k='-DISABLE1-', border_width=0,
button_color=(sg.theme_background_color(), sg.theme_background_color()), button_color=(sg.theme_background_color(), sg.theme_background_color()),
disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()), disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()),
metadata=BtnInfo(False)), metadata=BtnInfo(False)), sg.T('Disabled button color is\nbetter than other disabled button below')
], ],
[sg.Button(image_data=on_image, k='-TOGGLE2-', border_width=0, [sg.Button(image_data=on_image, k='-TOGGLE2-', border_width=0,
button_color=(sg.theme_background_color(), sg.theme_background_color()), button_color=(sg.theme_background_color(), sg.theme_background_color()),
disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()), disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()),
metadata=BtnInfo())], metadata=BtnInfo())],
[ sg.T('Disabled with GUI:', text_color='yellow')],
[sg.Button(image_data=on_image, k='-TOGGLE3-', border_width=0,
button_color=(sg.theme_background_color(), sg.theme_background_color()),
disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()),
disabled=True, metadata=BtnInfo()), sg.T('Note color has crosshatching')],
[ sg.T('Disabled with PySimpleGUI (ignored):', text_color='yellow')],
[sg.Button(image_data=on_image, k='-TOGGLE3-', border_width=0,
button_color=(sg.theme_background_color(), sg.theme_background_color()),
disabled_button_color=(sg.theme_background_color(), sg.theme_background_color()),
disabled=sg.BUTTON_DISABLED_MEANS_IGNORE, metadata=BtnInfo())],
[sg.T(size=(40,1), k='-STATUS-')],
[sg.Button('Exit')]] [sg.Button('Exit')]]
window = sg.Window('Window Title', layout, font='_ 14', finalize=True) window = sg.Window('Window Title', layout, font='_ 14', finalize=True)
@ -80,7 +92,7 @@ def main():
window['-TOGGLE1-'].update(disabled=False, image_data=on_image) window['-TOGGLE1-'].update(disabled=False, image_data=on_image)
elif window['-TOGGLE1-'].metadata.state is False: elif window['-TOGGLE1-'].metadata.state is False:
window['-TOGGLE1-'].update(disabled=False, image_data=off_image) window['-TOGGLE1-'].update(disabled=False, image_data=off_image)
window['-STATUS-'].update(f'event {event} button state = {window[event].metadata.state}')
window.close() window.close()
# Define the button graphic base 64 strings and then call the main function # Define the button graphic base 64 strings and then call the main function

View File

@ -1,46 +0,0 @@
#!/usr/bin/env python
import PySimpleGUI as sg
"""
Demonstrates the new change_submits parameter for inputtext elements
It ONLY submits when a button changes the field, not normal user input
Be careful on persistent forms to not clear the input
"""
layout = [[sg.Text('Test of reading input field')],
[sg.Text('This input is normal'), sg.Input()],
[sg.Text('This input change submits'),
sg.Input(change_submits=True)],
[sg.Text('This multiline input change submits'),
sg.ML('', change_submits=True)],
[sg.Text('This input is normal'),
sg.Input(), sg.FileBrowse()],
[sg.Text('File Browse submits'),
sg.Input(change_submits=True,
key='-in1-'), sg.FileBrowse()],
[sg.Text('Color Chooser submits'),
sg.Input(change_submits=True,
key='-in2-'), sg.ColorChooserButton('Color...', target=(sg.ThisRow, -1))],
[sg.Text('Folder Browse submits'),
sg.Input(change_submits=True,
key='-in3-'), sg.FolderBrowse()],
[sg.Text('Calendar Chooser submits'),
sg.Input(change_submits=True,
key='-in4-'), sg.CalendarButton('Date...', target=(sg.ThisRow, -1))],
[sg.Text('Disabled input submits'),
sg.Input(change_submits=True,
disabled=True,
key='_in5'), sg.FileBrowse()],
[sg.Text('This input clears after submit'),
sg.Input(change_submits=True, key='-in6-'), sg.FileBrowse()],
[sg.Button('Read')]]
window = sg.Window('Demonstration of InputText with change_submits',
layout, auto_size_text=False, default_element_size=(22, 1),
text_justification='right')
while True: # Event Loop
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED:
break
window.close()

View File

@ -10,11 +10,11 @@ sg.theme('GreenTan') # give our window a spiffy set of colors
layout = [[sg.Text('Your output will go here', size=(40, 1))], layout = [[sg.Text('Your output will go here', size=(40, 1))],
[sg.Output(size=(110, 20), font=('Helvetica 10'))], [sg.Output(size=(110, 20), font=('Helvetica 10'))],
[sg.Multiline(size=(70, 5), enter_submits=True, key='-QUERY-', do_not_clear=False), [sg.Multiline(size=(70, 5), enter_submits=False, key='-QUERY-', do_not_clear=False),
sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]] sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
window = sg.Window('Chat window', layout, font=('Helvetica', ' 13'), default_button_element_size=(8,2)) window = sg.Window('Chat window', layout, font=('Helvetica', ' 13'), default_button_element_size=(8,2), use_default_focus=False)
while True: # The Event Loop while True: # The Event Loop
event, value = window.read() event, value = window.read()
@ -23,6 +23,6 @@ while True: # The Event Loop
if event == 'SEND': if event == 'SEND':
query = value['-QUERY-'].rstrip() query = value['-QUERY-'].rstrip()
# EXECUTE YOUR COMMAND HERE # EXECUTE YOUR COMMAND HERE
print('The command you entered was {}'.format(query)) print('The command you entered was {}'.format(query), flush=True)
window.close() window.close()

BIN
DemoPrograms/exampleGIF.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB