diff --git a/Demo_All_Widgets.py b/Demo_All_Widgets.py index f983787e..b1991ad5 100644 --- a/Demo_All_Widgets.py +++ b/Demo_All_Widgets.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg sg.ChangeLookAndFeel('GreenTan') diff --git a/Demo_Borderless_Window.py b/Demo_Borderless_Window.py index 1d1f8479..f1e07b36 100644 --- a/Demo_Borderless_Window.py +++ b/Demo_Borderless_Window.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg """ Turn off padding in order to get a really tight looking layout. diff --git a/Demo_Button_Click.py b/Demo_Button_Click.py index 6295b151..28528a46 100644 --- a/Demo_Button_Click.py +++ b/Demo_Button_Click.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import winsound diff --git a/Demo_Button_States.py b/Demo_Button_States.py index 9c481ffd..729fa5ba 100644 --- a/Demo_Button_States.py +++ b/Demo_Button_States.py @@ -1,10 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg - +else: + import PySimpleGUI27 as sg """ Demonstrates using a "tight" layout with a Dark theme. Shows how button states can be controlled by a user application. The program manages the disabled/enabled diff --git a/Demo_Calendar.py b/Demo_Calendar.py index 473e414b..0b2df603 100644 --- a/Demo_Calendar.py +++ b/Demo_Calendar.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[sg.T('Calendar Test')], [sg.In('', size=(20,1), key='input')], diff --git a/Demo_Canvas.py b/Demo_Canvas.py index 81f1995e..22d77b04 100644 --- a/Demo_Canvas.py +++ b/Demo_Canvas.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [ [sg.Canvas(size=(150, 150), background_color='red', key='canvas')], diff --git a/Demo_Chat.py b/Demo_Chat.py index 5f6fc7a4..5b235c4c 100644 --- a/Demo_Chat.py +++ b/Demo_Chat.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg ''' A chat window. Add call to your send-routine, print the response and you're done diff --git a/Demo_Chat_With_History.py b/Demo_Chat_With_History.py index c9e14d33..652d4ca0 100644 --- a/Demo_Chat_With_History.py +++ b/Demo_Chat_With_History.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + ''' A chatbot with history Scroll up and down through prior commands using the arrow keys diff --git a/Demo_Chatterbot.py b/Demo_Chatterbot.py index 4a636aad..47ad334b 100644 --- a/Demo_Chatterbot.py +++ b/Demo_Chatterbot.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg from chatterbot import ChatBot import chatterbot.utils diff --git a/Demo_Color.py b/Demo_Color.py index 9a0dd188..5dcc23af 100644 --- a/Demo_Color.py +++ b/Demo_Color.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg MY_WINDOW_ICON = 'E:\\TheRealMyDocs\\Icons\\The Planets\\jupiter.ico' reverse = {} @@ -1702,10 +1702,14 @@ def main(): if hex_input == '' and len(drop_down_value) == 0: continue - if hex_input is not '' and hex_input[0] == '#': - color_hex = hex_input.upper() - color_name = get_name_from_hex(hex_input) - elif drop_down_value is not None: + if len(hex_input) != 0: + if hex_input[0] == '#': + color_hex = hex_input.upper() + color_name = get_name_from_hex(hex_input) + else: + color_name = hex_input + color_hex = get_hex_from_name(color_name) + elif drop_down_value is not None and len(drop_down_value) != 0: color_name = drop_down_value[0] color_hex = get_hex_from_name(color_name) diff --git a/Demo_Color_Names.py b/Demo_Color_Names.py index e7762c20..aeba15d0 100644 --- a/Demo_Color_Names.py +++ b/Demo_Color_Names.py @@ -1,9 +1,11 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + + """ Shows a big chart of colors... give it a few seconds to create it diff --git a/Demo_Color_Names_Smaller_List.py b/Demo_Color_Names_Smaller_List.py index b880ff78..fac8fe5c 100644 --- a/Demo_Color_Names_Smaller_List.py +++ b/Demo_Color_Names_Smaller_List.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + """ Color names courtesy of Big Daddy's Wiki-Python http://www.wikipython.com/tkinter-ttk-tix/summary-information/colors/ diff --git a/Demo_Columns.py b/Demo_Columns.py index 1f15c63d..dd68aa86 100644 --- a/Demo_Columns.py +++ b/Demo_Columns.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg sg.ChangeLookAndFeel('BlueMono') diff --git a/Demo_Compare_Files.py b/Demo_Compare_Files.py index 848fd10b..a6a8c289 100644 --- a/Demo_Compare_Files.py +++ b/Demo_Compare_Files.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + # sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT) def GetFilesToCompare(): diff --git a/Demo_DOC_Viewer_PIL.py b/Demo_DOC_Viewer_PIL.py index 927027f1..0287cc90 100644 --- a/Demo_DOC_Viewer_PIL.py +++ b/Demo_DOC_Viewer_PIL.py @@ -31,7 +31,11 @@ pixmaps and page re-visits will re-use a once-created display list. """ import sys import fitz -import PySimpleGUI as sg +import sys +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import tkinter as tk from PIL import Image, ImageTk import time diff --git a/Demo_Design_Patterns.py b/Demo_Design_Patterns.py index 88ab2fc1..aa56ddf0 100644 --- a/Demo_Design_Patterns.py +++ b/Demo_Design_Patterns.py @@ -9,7 +9,11 @@ These are the accepted design patterns that cover the two primary use cases # ---------------------------------# # DESIGN PATTERN 1 - Simple Window # # ---------------------------------# -import PySimpleGUI as sg +import sys +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[ sg.Text('My layout') ]] @@ -20,7 +24,11 @@ button, value = window.Read() # -------------------------------------# # DESIGN PATTERN 2 - Persistent Window # # -------------------------------------# -import PySimpleGUI as sg +import sys +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[ sg.Text('My layout') ]] @@ -34,7 +42,11 @@ while True: # Event Loop # ------------------------------------------------------------------# # DESIGN PATTERN 3 - Persistent Window with "early update" required # # ------------------------------------------------------------------# -import PySimpleGUI as sg +import sys +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[ sg.Text('My layout') ]] diff --git a/Demo_Desktop_Floating_Toolbar.py b/Demo_Desktop_Floating_Toolbar.py index a34b4c10..c50d8a90 100644 --- a/Demo_Desktop_Floating_Toolbar.py +++ b/Demo_Desktop_Floating_Toolbar.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import subprocess import os diff --git a/Demo_Desktop_Widget_CPU_Graph.py b/Demo_Desktop_Widget_CPU_Graph.py index 528c336a..9f2f8984 100644 --- a/Demo_Desktop_Widget_CPU_Graph.py +++ b/Demo_Desktop_Widget_CPU_Graph.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +import sys +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import time import random import psutil diff --git a/Demo_Desktop_Widget_CPU_Utilization.py b/Demo_Desktop_Widget_CPU_Utilization.py index fedd6260..af970e62 100644 --- a/Demo_Desktop_Widget_CPU_Utilization.py +++ b/Demo_Desktop_Widget_CPU_Utilization.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +import sys +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import psutil import time from threading import Thread diff --git a/Demo_Desktop_Widget_CPU_Utilization_Simple.py b/Demo_Desktop_Widget_CPU_Utilization_Simple.py index 3ce7fb59..afb5efd4 100644 --- a/Demo_Desktop_Widget_CPU_Utilization_Simple.py +++ b/Demo_Desktop_Widget_CPU_Utilization_Simple.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +import sys +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import psutil diff --git a/Demo_Desktop_Widget_Timer.py b/Demo_Desktop_Widget_Timer.py index 46a5b3fc..5d15f079 100644 --- a/Demo_Desktop_Widget_Timer.py +++ b/Demo_Desktop_Widget_Timer.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +import sys +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import time """ @@ -22,7 +23,7 @@ layout = [[sg.Text('')], sg.ReadButton('Reset', button_color=('white', '#007339'), key='Reset'), sg.Exit(button_color=('white', 'firebrick4'), key='Exit')]] -window = sg.Window('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout) +window = sg.Window('Running Timer', no_titlebar=False, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout) # ---------------- main loop ---------------- current_time = 0 diff --git a/Demo_Disable_Elements.py b/Demo_Disable_Elements.py index ed0753e3..d927d5a1 100644 --- a/Demo_Disable_Elements.py +++ b/Demo_Disable_Elements.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +import sys +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg sg.ChangeLookAndFeel('Dark') sg.SetOptions(element_padding=(0, 0)) diff --git a/Demo_DuplicateFileFinder.py b/Demo_DuplicateFileFinder.py index ef5c46b9..eebe5ee1 100644 --- a/Demo_DuplicateFileFinder.py +++ b/Demo_DuplicateFileFinder.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +import sys +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import hashlib import os diff --git a/Demo_Fill_Form.py b/Demo_Fill_Form.py index d1a0daad..cbfed70e 100644 --- a/Demo_Fill_Form.py +++ b/Demo_Fill_Form.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +import sys +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg def Everything(): sg.ChangeLookAndFeel('TanBlue') diff --git a/Demo_Font_Sizer.py b/Demo_Font_Sizer.py index 861b0b8e..56983819 100644 --- a/Demo_Font_Sizer.py +++ b/Demo_Font_Sizer.py @@ -1,8 +1,12 @@ # Testing async form, see if can have a slider # that adjusts the size of text displayed +import sys +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg -import PySimpleGUI as sg fontSize = 12 layout = [[sg.Spin([sz for sz in range(6, 172)], font=('Helvetica 20'), initial_value=fontSize, change_submits=True, key='spin'), sg.Slider(range=(6,172), orientation='h', size=(10,20), change_submits=True, key='slider', font=('Helvetica 20')), sg.Text("Aa", size=(2, 1), font="Helvetica " + str(fontSize), key='text')]] diff --git a/Demo_Func_Callback_Simulation.py b/Demo_Func_Callback_Simulation.py index f9924686..a6bf0095 100644 --- a/Demo_Func_Callback_Simulation.py +++ b/Demo_Func_Callback_Simulation.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[sg.Text('Filename', )], [sg.Input(), sg.FileBrowse()], diff --git a/Demo_GoodColors.py b/Demo_GoodColors.py index f9cf5154..8ec0fee7 100644 --- a/Demo_GoodColors.py +++ b/Demo_GoodColors.py @@ -1,53 +1,52 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg -import time - +else: + import PySimpleGUI27 as sg + def main(): # ------- Make a new Window ------- # - window = gg.Window('GoodColors', auto_size_text=True, default_element_size=(30,2)) - window.AddRow(gg.Text('Having trouble picking good colors? Try one of the colors defined by PySimpleGUI')) - window.AddRow(gg.Text('Here come the good colors as defined by PySimpleGUI')) + window = sg.Window('GoodColors', auto_size_text=True, default_element_size=(30,2)) + window.AddRow(sg.Text('Having trouble picking good colors? Try one of the colors defined by PySimpleGUI')) + window.AddRow(sg.Text('Here come the good colors as defined by PySimpleGUI')) #===== Show some nice BLUE colors with yellow text ===== ===== ===== ===== ===== ===== =====# - text_color = gg.YELLOWS[0] - buttons = (gg.Button('BLUES[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(gg.BLUES)) - window.AddRow(gg.T('Button Colors Using PySimpleGUI.BLUES')) + text_color = sg.YELLOWS[0] + buttons = (sg.Button('BLUES[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(sg.BLUES)) + window.AddRow(sg.T('Button Colors Using PySimpleGUI.BLUES')) window.AddRow(*buttons) - window.AddRow(gg.Text('_' * 100, size=(65, 1))) + window.AddRow(sg.Text('_' * 100, size=(65, 1))) #===== Show some nice PURPLE colors with yellow text ===== ===== ===== ===== ===== ===== =====# - buttons = (gg.Button('PURPLES[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(gg.PURPLES)) - window.AddRow(gg.T('Button Colors Using PySimpleGUI.PURPLES')) + buttons = (sg.Button('PURPLES[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(sg.PURPLES)) + window.AddRow(sg.T('Button Colors Using PySimpleGUI.PURPLES')) window.AddRow(*buttons) - window.AddRow(gg.Text('_' * 100, size=(65, 1))) + window.AddRow(sg.Text('_' * 100, size=(65, 1))) #===== Show some nice GREEN colors with yellow text ===== ===== ===== ===== ===== ===== =====# - buttons = (gg.Button('GREENS[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(gg.GREENS)) - window.AddRow(gg.T('Button Colors Using PySimpleGUI.GREENS')) + buttons = (sg.Button('GREENS[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(sg.GREENS)) + window.AddRow(sg.T('Button Colors Using PySimpleGUI.GREENS')) window.AddRow(*buttons) - window.AddRow(gg.Text('_' * 100, size=(65, 1))) + window.AddRow(sg.Text('_' * 100, size=(65, 1))) #===== Show some nice TAN colors with yellow text ===== ===== ===== ===== ===== ===== =====# - text_color = gg.GREENS[0] # let's use GREEN text on the tan - buttons = (gg.Button('TANS[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(gg.TANS)) - window.AddRow(gg.T('Button Colors Using PySimpleGUI.TANS')) + text_color = sg.GREENS[0] # let's use GREEN text on the tan + buttons = (sg.Button('TANS[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(sg.TANS)) + window.AddRow(sg.T('Button Colors Using PySimpleGUI.TANS')) window.AddRow(*buttons) - window.AddRow(gg.Text('_' * 100, size=(65, 1))) + window.AddRow(sg.Text('_' * 100, size=(65, 1))) #===== Show some nice YELLOWS colors with black text ===== ===== ===== ===== ===== ===== =====# text_color = 'black' # let's use black text on the tan - buttons = (gg.Button('YELLOWS[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(gg.YELLOWS)) - window.AddRow(gg.T('Button Colors Using PySimpleGUI.YELLOWS')) + buttons = (sg.Button('YELLOWS[{}]\n{}'.format(j, c), button_color=(text_color, c), size=(10,2)) for j, c in enumerate(sg.YELLOWS)) + window.AddRow(sg.T('Button Colors Using PySimpleGUI.YELLOWS')) window.AddRow(*buttons) - window.AddRow(gg.Text('_' * 100, size=(65, 1))) + window.AddRow(sg.Text('_' * 100, size=(65, 1))) #===== Add a click me button for fun and SHOW the window ===== ===== ===== ===== ===== ===== =====# - window.AddRow(gg.Button('Click ME!')) + window.AddRow(sg.Button('Click ME!')) (button, value) = window.Show() # show it! diff --git a/Demo_Graph_Drawing.py b/Demo_Graph_Drawing.py index a8b3246c..193da119 100644 --- a/Demo_Graph_Drawing.py +++ b/Demo_Graph_Drawing.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0,0), graph_top_right=(400, 400), background_color='red', key='graph')], [sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue'), sg.ReadButton('Move')]] diff --git a/Demo_Graph_Element.py b/Demo_Graph_Element.py index 9c047a5e..e683f279 100644 --- a/Demo_Graph_Element.py +++ b/Demo_Graph_Element.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + import ping from threading import Thread import time diff --git a/Demo_Graph_Element_Sine_Wave.py b/Demo_Graph_Element_Sine_Wave.py index 784347dd..997d804b 100644 --- a/Demo_Graph_Element_Sine_Wave.py +++ b/Demo_Graph_Element_Sine_Wave.py @@ -1,16 +1,20 @@ -#!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import math - -layout = [[sg.T('Example of Using Math with a Graph', justification='center', size=(40,1), relief=sg.RELIEF_RAISED)], - [sg.Graph(canvas_size=(400, 400), graph_bottom_left=(-105,-105), graph_top_right=(105,105), background_color='white', key='graph', tooltip='This is a cool graph!')],] +layout = [[sg.T('Example of Using Math with a Graph', justification='center', + size=(50,1), relief=sg.RELIEF_SUNKEN)], + [sg.Graph(canvas_size=(400, 400), + graph_bottom_left=(-105,-105), + graph_top_right=(105,105), + background_color='white', + key='graph')],] window = sg.Window('Graph of Sine Function', grab_anywhere=True).Layout(layout).Finalize() + graph = window.FindElement('graph') # Draw axis @@ -27,6 +31,7 @@ for y in range(-100, 101, 20): if y != 0: graph.DrawText( y, (-10,y), color='blue') + # Draw Graph for x in range(-100,100): y = math.sin(x/20)*50 diff --git a/Demo_Graph_Noise.py b/Demo_Graph_Noise.py index f290eb65..8af8cf15 100644 --- a/Demo_Graph_Noise.py +++ b/Demo_Graph_Noise.py @@ -1,11 +1,10 @@ #!/usr/bin/env python import sys - -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg -import time +else: + import PySimpleGUI27 as sg + import random import sys @@ -47,6 +46,7 @@ def main(): while True: # time.sleep(.2) button, values = window.ReadNonBlocking() + print(button, values) if button == 'Quit' or values is None: break graph_offset = random.randint(-10, 10) diff --git a/Demo_HowDoI.py b/Demo_HowDoI.py index e9761acd..e05db15b 100644 --- a/Demo_HowDoI.py +++ b/Demo_HowDoI.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import subprocess diff --git a/Demo_Img_Viewer.py b/Demo_Img_Viewer.py index 2c36376a..0f279ff6 100644 --- a/Demo_Img_Viewer.py +++ b/Demo_Img_Viewer.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import os from PIL import Image, ImageTk import io diff --git a/Demo_Keyboard.py b/Demo_Keyboard.py index 030bdcd0..11510604 100644 --- a/Demo_Keyboard.py +++ b/Demo_Keyboard.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg # Recipe for getting keys, one at a time as they are released # If want to use the space bar, then be sure and disable the "default focus" diff --git a/Demo_Keyboard_Realtime.py b/Demo_Keyboard_Realtime.py index 5786b58b..460d79d1 100644 --- a/Demo_Keyboard_Realtime.py +++ b/Demo_Keyboard_Realtime.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[sg.Text("Hold down a key")], [sg.Button("OK")]] diff --git a/Demo_Keypad.py b/Demo_Keypad.py index 65aa42f8..a66685c4 100644 --- a/Demo_Keypad.py +++ b/Demo_Keypad.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg # Demonstrates a number of PySimpleGUI features including: # Default element size diff --git a/Demo_MIDI_Player.py b/Demo_MIDI_Player.py index dd9f568f..fa4ea87c 100644 --- a/Demo_MIDI_Player.py +++ b/Demo_MIDI_Player.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import os import mido import time diff --git a/Demo_Machine_Learning.py b/Demo_Machine_Learning.py index aa0ce638..42b1caa6 100644 --- a/Demo_Machine_Learning.py +++ b/Demo_Machine_Learning.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + def MachineLearningGUI(): sg.SetOptions(text_justification='right') diff --git a/Demo_Matplotlib.py b/Demo_Matplotlib.py index 6c97132c..32e47960 100644 --- a/Demo_Matplotlib.py +++ b/Demo_Matplotlib.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import matplotlib matplotlib.use('TkAgg') @@ -114,12 +114,12 @@ fig = plt.gcf() # if using Pyplot then get the figure from the plot # --------------------------------------------------------------------------------# figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds # define the form layout -layout = [[sg.Text('Plot test')], +layout = [[sg.Text('Plot test', font='Any 18')], [sg.Canvas(size=(figure_w, figure_h), key='canvas')], [sg.OK(pad=((figure_w / 2, 0), 3), size=(4, 2))]] # create the form and show it without the plot -window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI').Layout(layout).Finalize() +window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI', force_toplevel=True).Layout(layout).Finalize() # add the plot to the window fig_photo = draw_figure(window.FindElement('canvas').TKCanvas, fig) diff --git a/Demo_Matplotlib_Animated.py b/Demo_Matplotlib_Animated.py index de50ddc2..7ea71601 100644 --- a/Demo_Matplotlib_Animated.py +++ b/Demo_Matplotlib_Animated.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + from random import randint from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg from matplotlib.figure import Figure diff --git a/Demo_Matplotlib_Animated_Scatter.py b/Demo_Matplotlib_Animated_Scatter.py index 8461f2fd..49135aa8 100644 --- a/Demo_Matplotlib_Animated_Scatter.py +++ b/Demo_Matplotlib_Animated_Scatter.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + from random import randint import PySimpleGUI as sg from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg diff --git a/Demo_Matplotlib_Browser.py b/Demo_Matplotlib_Browser.py index 79cbfdcf..f3095678 100644 --- a/Demo_Matplotlib_Browser.py +++ b/Demo_Matplotlib_Browser.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import matplotlib matplotlib.use('TkAgg') from matplotlib.backends.backend_tkagg import FigureCanvasAgg diff --git a/Demo_Matplotlib_Ping_Graph.py b/Demo_Matplotlib_Ping_Graph.py index 092a2898..31829750 100644 --- a/Demo_Matplotlib_Ping_Graph.py +++ b/Demo_Matplotlib_Ping_Graph.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasAgg import matplotlib.backends.tkagg as tkagg diff --git a/Demo_Matplotlib_Ping_Graph_Large.py b/Demo_Matplotlib_Ping_Graph_Large.py index 02486899..a7328a70 100644 --- a/Demo_Matplotlib_Ping_Graph_Large.py +++ b/Demo_Matplotlib_Ping_Graph_Large.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import matplotlib.pyplot as plt import ping from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg diff --git a/Demo_Media_Player.py b/Demo_Media_Player.py index 47b75338..1a4e0d5f 100644 --- a/Demo_Media_Player.py +++ b/Demo_Media_Player.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg # # An Async Demonstration of a media player diff --git a/Demo_Menus.py b/Demo_Menus.py index c0df56cb..b57e2608 100644 --- a/Demo_Menus.py +++ b/Demo_Menus.py @@ -1,10 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg - +else: + import PySimpleGUI27 as sg """ Demonstration of MENUS! How do menus work? Like buttons is how. @@ -27,13 +26,13 @@ def TestMenus(): sg.SetOptions(element_padding=(0, 0)) # ------ Menu Definition ------ # - menu_def = [['File', ['Open', 'Save', 'Properties']], + menu_def = [['File', ['O_&pen', 'Save', '---', 'Properties']], ['Edit', ['Paste', ['Special', 'Normal',], 'Undo'],], ['Help', 'About...'],] # ------ GUI Defintion ------ # layout = [ - [sg.Menu(menu_def, tearoff=True)], + [sg.Menu(menu_def, tearoff=False)], [sg.Output(size=(60,20))], [sg.In('Test', key='input', do_not_clear=True)] ] @@ -49,7 +48,9 @@ def TestMenus(): print('Button = ', button) # ------ Process menu choices ------ # if button == 'About...': + window.Disable() sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...') + window.Enable() elif button == 'Open': filename = sg.PopupGetFile('file to open', no_window=True) print(filename) diff --git a/Demo_NonBlocking_Form.py b/Demo_NonBlocking_Form.py index a016a197..0c489c69 100644 --- a/Demo_NonBlocking_Form.py +++ b/Demo_NonBlocking_Form.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import time # Window that doen't block diff --git a/Demo_OpenCV.py b/Demo_OpenCV.py index 7909f6fb..84f8331c 100644 --- a/Demo_OpenCV.py +++ b/Demo_OpenCV.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import cv2 as cv from PIL import Image import tempfile diff --git a/Demo_PDF_Viewer.py b/Demo_PDF_Viewer.py index 96e55fd0..5d9b150c 100644 --- a/Demo_PDF_Viewer.py +++ b/Demo_PDF_Viewer.py @@ -34,7 +34,10 @@ pixmaps and page re-visits will re-use a once-created display list. """ import sys import fitz -import PySimpleGUI as sg +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg from sys import exit as exit from binascii import hexlify diff --git a/Demo_PNG_Viewer.py b/Demo_PNG_Viewer.py index 60aa1d8c..75aac14a 100644 --- a/Demo_PNG_Viewer.py +++ b/Demo_PNG_Viewer.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import os from sys import exit as exit diff --git a/Demo_Password_Login.py b/Demo_Password_Login.py index cc326fc3..16a4a840 100644 --- a/Demo_Password_Login.py +++ b/Demo_Password_Login.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import hashlib from sys import exit as exit diff --git a/Demo_Pi_LEDs.py b/Demo_Pi_LEDs.py index fe29aadf..bd8991e5 100644 --- a/Demo_Pi_LEDs.py +++ b/Demo_Pi_LEDs.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg # GUI for switching an LED on and off to GPIO14 # GPIO and time library: @@ -32,13 +32,13 @@ def FlashLED(): GPIO.output(14, GPIO.LOW) time.sleep(0.5) -layout = [[rg.T('Raspberry Pi LEDs')], - [rg.T('', size=(14, 1), key='output')], - [rg.ReadButton('Switch LED')], - [rg.ReadButton('Flash LED')], - [rg.Exit()]] +layout = [[sg.T('Raspberry Pi LEDs')], + [sg.T('', size=(14, 1), key='output')], + [sg.ReadButton('Switch LED')], + [sg.ReadButton('Flash LED')], + [sg.Exit()]] -window = rg.Window('Raspberry Pi GUI', grab_anywhere=False).Layout(layout) +window = sg.Window('Raspberry Pi GUI', grab_anywhere=False).Layout(layout) while True: button, values = window.Read() @@ -53,4 +53,4 @@ while True: FlashLED() window.FindElement('output').Update('') -rg.Popup('Done... exiting') +sg.Popup('Done... exiting') diff --git a/Demo_Pi_Robotics.py b/Demo_Pi_Robotics.py index ed31ce75..494dd200 100644 --- a/Demo_Pi_Robotics.py +++ b/Demo_Pi_Robotics.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg # Robotics design pattern # Uses Realtime Buttons to simulate the controls for a robot diff --git a/Demo_Ping_Line_Graph.py b/Demo_Ping_Line_Graph.py index 163f4dc9..2395f885 100644 --- a/Demo_Ping_Line_Graph.py +++ b/Demo_Ping_Line_Graph.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + from threading import Thread import time from sys import exit as exit diff --git a/Demo_Pong.py b/Demo_Pong.py index 1732aa97..2e8b5cd2 100644 --- a/Demo_Pong.py +++ b/Demo_Pong.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import random import time from sys import exit as exit diff --git a/Demo_Popups.py b/Demo_Popups.py index 2951bca1..cdac857d 100644 --- a/Demo_Popups.py +++ b/Demo_Popups.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg # Here, have some windows on me.... [sg.PopupNoWait(location=(10*x,0)) for x in range(10)] diff --git a/Demo_Progress_Meters.py b/Demo_Progress_Meters.py index 738b861e..8386a9d7 100644 --- a/Demo_Progress_Meters.py +++ b/Demo_Progress_Meters.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg from time import sleep from sys import exit as exit diff --git a/Demo_Script_Launcher.py b/Demo_Script_Launcher.py index cc4b6efd..088aa5fc 100644 --- a/Demo_Script_Launcher.py +++ b/Demo_Script_Launcher.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import glob import ntpath import subprocess diff --git a/Demo_Script_Parameters.py b/Demo_Script_Parameters.py index 3ae20cdb..93dfeb6b 100644 --- a/Demo_Script_Parameters.py +++ b/Demo_Script_Parameters.py @@ -1,10 +1,10 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg -import sys +else: + import PySimpleGUI27 as sg + ''' Quickly add a GUI to your script! diff --git a/Demo_Spinner_Compound_Element.py b/Demo_Spinner_Compound_Element.py index fafb049a..219149bd 100644 --- a/Demo_Spinner_Compound_Element.py +++ b/Demo_Spinner_Compound_Element.py @@ -1,10 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg - +else: + import PySimpleGUI27 as sg """ Demo of how to combine elements into your own custom element """ diff --git a/Demo_Super_Simple_Form.py b/Demo_Super_Simple_Form.py index da8ec34f..df7575a2 100644 --- a/Demo_Super_Simple_Form.py +++ b/Demo_Super_Simple_Form.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg """ Simple Form showing how to use keys on your input fields diff --git a/Demo_Table_CSV.py b/Demo_Table_CSV.py index c50b9b2b..ae4e9423 100644 --- a/Demo_Table_CSV.py +++ b/Demo_Table_CSV.py @@ -1,11 +1,11 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import csv -import sys + def table_example(): filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),)) diff --git a/Demo_Table_Element.py b/Demo_Table_Element.py index f810dfa8..237b575d 100644 --- a/Demo_Table_Element.py +++ b/Demo_Table_Element.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import csv diff --git a/Demo_Table_Pandas.py b/Demo_Table_Pandas.py index 21c99923..022aa1bf 100644 --- a/Demo_Table_Pandas.py +++ b/Demo_Table_Pandas.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import pandas as pd diff --git a/Demo_Table_Simulation.py b/Demo_Table_Simulation.py index 87062ff9..0889ed4f 100644 --- a/Demo_Table_Simulation.py +++ b/Demo_Table_Simulation.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import csv diff --git a/Demo_Tabs.py b/Demo_Tabs.py index 270bdc17..673c9307 100644 --- a/Demo_Tabs.py +++ b/Demo_Tabs.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg tab1_layout = [[sg.T('This is inside tab 1')]] diff --git a/Demo_Tabs_Nested.py b/Demo_Tabs_Nested.py index ff4bfa37..1c0b87b6 100644 --- a/Demo_Tabs_Nested.py +++ b/Demo_Tabs_Nested.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg sg.ChangeLookAndFeel('GreenTan') tab2_layout = [[sg.T('This is inside tab 2')], diff --git a/Demo_Template.py b/Demo_Template.py index 4a3a508f..92a194d2 100644 --- a/Demo_Template.py +++ b/Demo_Template.py @@ -1,14 +1,14 @@ -#choose one of these are your starting point +#choose one of these are your starting point. Copy, paste, have fun # ---------------------------------# # DESIGN PATTERN 1 - Simple Window # # ---------------------------------# #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[ sg.Text('My layout') ]] @@ -21,10 +21,10 @@ button, value = window.Read() # -------------------------------------# #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg layout = [[ sg.Text('My layout') ]] diff --git a/Demo_Youtube-dl_Frontend.py b/Demo_Youtube-dl_Frontend.py index 6b7dba3c..6e0f30e4 100644 --- a/Demo_Youtube-dl_Frontend.py +++ b/Demo_Youtube-dl_Frontend.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import sys -if sys.version_info[0] < 3: - import PySimpleGUI27 as sg -else: +if sys.version_info[0] >= 3: import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg import subprocess """ diff --git a/ProgrammingClassExamples/1b PSG (Format).py b/ProgrammingClassExamples/1b PSG (Format).py index 218be402..d5b5540b 100644 --- a/ProgrammingClassExamples/1b PSG (Format).py +++ b/ProgrammingClassExamples/1b PSG (Format).py @@ -16,7 +16,7 @@ sg.SetOptions (background_color = 'LightBlue', #adjust widths layout = [ [sg.Text('Celcius', size =(12,1)), sg.InputText(size = (8,1))], - [sg.Submit()], + [sg.Submit()] ] window = sg.Window('Converter').Layout(layout) diff --git a/ProgrammingClassExamples/4a PSG (Sliders and combo).py b/ProgrammingClassExamples/4a PSG (Sliders and combo).py index 67a930fd..f933a16d 100644 --- a/ProgrammingClassExamples/4a PSG (Sliders and combo).py +++ b/ProgrammingClassExamples/4a PSG (Sliders and combo).py @@ -4,6 +4,8 @@ import PySimpleGUI as sg +#use of Column to help with layout - vertical sliders take up space + column1 = [ [sg.Text('Pick operation', size = (15,1), font = ('Calibri', 12, 'bold'))], [sg.InputCombo(['Add','Subtract','Multiply','Divide'], size = (10,6))], @@ -20,8 +22,12 @@ layout = [ sg.Slider(range = (-9, 9),orientation = 'v', size = (5, 20), default_value = 0), sg.Text(' '), sg.Column(column1), sg.Column(column2)]] -window = sg.Window('Enter & Display Data', grab_anywhere=False).Layout(layout) +#added grab_anywhere to when moving slider, who window doesn't move. +window = sg.Window('Enter & Display Data',grab_anywhere = False).Layout(layout) + +#Get selection from combo: value[2] +#Slider values: value[0] and value[1] while True: button, value = window.Read() if button is not None: @@ -31,11 +37,10 @@ while True: result = value[0] * value[1] elif value[2] == 'Subtract': result = value[0] - value[1] - elif value[2] == 'Divide': + elif value[2] == 'Divide': #check for zero if value[1] ==0: sg.Popup('Second value can\'t be zero') - if value[0] == 0: - result = 'NA' + result = 'NA' else: result = value[0] / value[1] window.FindElement('result').Update(result) diff --git a/ProgrammingClassExamples/4b PSG (Spinner and combo) .py b/ProgrammingClassExamples/4b PSG (Spinner and combo) .py index b4b61fc0..b41e8478 100644 --- a/ProgrammingClassExamples/4b PSG (Spinner and combo) .py +++ b/ProgrammingClassExamples/4b PSG (Spinner and combo) .py @@ -7,19 +7,20 @@ sg.SetOptions(font= ('Calibri', 12, 'bold')) layout = [ [sg.Text('Spinner and Combo box demo', font = ('Calibri', 14, 'bold'))], - [sg.Spin([sz for sz in range (-9,10)], initial_value = 0), - sg.Spin([sz for sz in range (-9,10)], initial_value = 0), - sg.Text('Pick operation', size = (13,1)), + [sg.Spin([sz for sz in range (-9,10)], size = (2,1),initial_value = 0), + sg.Spin([sz for sz in range (-9,10)], size = (2,1), initial_value = 0), + sg.Text('Pick operation ->', size = (15,1)), sg.InputCombo(['Add','Subtract','Multiply','Divide'], size = (8,6))], - [sg.Text('Result: ')],[sg.InputText(size = (6,1), key = 'result'), + [sg.Text('Result: ')],[sg.InputText(size = (5,1), key = 'result'), sg.ReadButton('Calculate', button_color = ('White', 'Red'))]] -window = sg.Window('Enter & Display Data', grab_anywhere=False).Layout(layout) +window = sg.Window('Enter & Display Data', grab_anywhere= False).Layout(layout) while True: button, value = window.Read() if button is not None: + #convert returned values to integers val = [int(value[0]), int(value[1])] if value[2] == 'Add': result = val[0] + val[1] diff --git a/ProgrammingClassExamples/5a PSG (listboxes add remove).py b/ProgrammingClassExamples/5a PSG (listboxes add remove).py new file mode 100644 index 00000000..7b60504e --- /dev/null +++ b/ProgrammingClassExamples/5a PSG (listboxes add remove).py @@ -0,0 +1,39 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +import PySimpleGUI as sg + +sg.ChangeLookAndFeel('BlueMono') + +#use column feature with height listbox takes up +column1 = [ + [sg.Text('Add or Delete Items\nfrom a Listbox', font = ('Arial', 12, 'bold'))], + [sg.InputText( size = (15,1), key = 'add'), sg.ReadButton('Add')], + [sg.ReadButton('Delete selected entry')]] + +List = ['Austalia', 'Canada', 'Greece'] #initial listbox entries + +#add initial List to listbox +layout = [ + [sg.Listbox(values=[l for l in List], size = (30,8), key ='listbox'), + sg.Column(column1)]] + +window = sg.Window('Listbox').Layout(layout) + +while True: + button, value = window.Read() + if button is not None: + #value[listbox] returns a list + if button == 'Delete selected entry': #using value[listbox][0] give the string + if value['listbox'] == []: #ensure something is selected + sg.Popup('Error','You must select a Country') + else: + List.remove(value['listbox'][0]) #find and remove this + if button == 'Add': + List.append(value['add']) #add string in add box to list + List.sort() #sort + #update listbox + window.FindElement('listbox').Update(List) + else: + break diff --git a/ProgrammingClassExamples/6a PSG search.py b/ProgrammingClassExamples/6a PSG search.py new file mode 100644 index 00000000..090ba7b2 --- /dev/null +++ b/ProgrammingClassExamples/6a PSG search.py @@ -0,0 +1,78 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +import PySimpleGUI as sg + +sg.SetOptions (font =('Calibri',12,'bold')) + +layout =[[sg.Text('Search Demo', font =('Calibri', 18, 'bold')), sg.ReadButton('Show Names')], +[sg.Text('',size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display1'), + sg.Text('',size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display2')], + [sg.Text('_'*32,font = ('Calibri', 12))], + [sg.InputText(size = (14,1), key = 'linear'), sg.InputText(size = (14,1), key = 'binary')], + [sg.ReadButton('Linear Search', size = (13,1)), sg.ReadButton('Binary Search', size = (14,1))], + ] +window = sg.Window('Search Demo').Layout(layout) + +#names for Demo, could be loaded from a file +Names = ['Roberta', 'Kylie', 'Jenny', 'Helen', + 'Andrea', 'Meredith','Deborah','Pauline', + 'Belinda', 'Wendy'] + +SortedNames = ['Andrea','Belinda','Deborah','Helen', + 'Jenny','Kylie','Meredith','Pauline', + 'Roberta','Wendy'] + +#function to display list +def displayList(List, display): + names = '' + for l in List: #add list elements with new line + names = names + l + '\n' + window.FindElement(display).Update(names) + +#Linear Search - no need for Ordered list +def linearSearch(): + L = Names[:] + found = False + for l in L: + if l == value['linear']: #Check each value + found = True + window.FindElement('display1').Update('Linear search\n' + l + ' found.') + break + if not found: + window.FindElement('display1').Update(value['linear'] + ' was \nNot found') + +#Binary Search - only works for ordered lists +def binarySearch(): + L = SortedNames[:] + lo = 0 + hi = len(L)-1 + found = False #Start with found is Flase + while lo <= hi: + mid = (lo + hi) //2 #Start in middle + if L[mid] == value['binary']: #get the value from the search box + window.FindElement('display2').Update('Binary search\n' + L[mid] + ' found.') + found = True #If found display + break #and stop + elif L[mid] < value['binary']: + lo = mid + 1 #Search in top half + else: + hi = mid - 1 #Search in lower half + if not found: #If we get to end - display not found + window.FindElement('display2').Update(value['binary'] + ' was \nNot found') + +while True: + button, value = window.Read() + + if button is not None: + if button == 'Show Names': #show names - unordered and sorted + displayList(Names,'display1') + displayList(SortedNames, 'display2') + if button == 'Linear Search': #Find and display + linearSearch() + if button == 'Binary Search': #Find and display + binarySearch() + else: + break + diff --git a/ProgrammingClassExamples/6b PSG search (disabled buttons).py b/ProgrammingClassExamples/6b PSG search (disabled buttons).py new file mode 100644 index 00000000..2e1dfd83 --- /dev/null +++ b/ProgrammingClassExamples/6b PSG search (disabled buttons).py @@ -0,0 +1,82 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +import PySimpleGUI as sg + +sg.SetOptions (font =('Calibri',12,'bold')) + +layout =[[sg.Text('Search Demo', font =('Calibri', 18, 'bold')), sg.ReadButton('Show Names')], +[sg.Text('',size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display1'), + sg.Text('',size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display2')], + [sg.Text('_'*32,font = ('Calibri', 12))], + [sg.InputText(size = (14,1), key = 'linear'), sg.InputText(size = (14,1), key = 'binary')], + [sg.ReadButton('Linear Search', size = (13,1),key = 'ls'), sg.ReadButton('Binary Search', size = (14,1),key='bs')], + ] +window = sg.Window('Search Demo').Layout(layout) +window.Finalize() #finalize allows the disabling +window.FindElement('ls').Update(disabled=True) #of the two buttons +window.FindElement('bs').Update(disabled=True) + +#names for Demo, could be loaded from a file +Names = ['Roberta', 'Kylie', 'Jenny', 'Helen', + 'Andrea', 'Meredith','Deborah','Pauline', + 'Belinda', 'Wendy'] + +SortedNames = ['Andrea','Belinda','Deborah','Helen', + 'Jenny','Kylie','Meredith','Pauline', + 'Roberta','Wendy'] + +#function to display list +def displayList(List, display): + names = '' + for l in List: #add list elements with new line + names = names + l + '\n' + window.FindElement(display).Update(names) + window.FindElement('ls').Update(disabled=False) #enable buttons now + window.FindElement('bs').Update(disabled=False) #now data loaded + +#Linear Search - no need for Ordered list +def linearSearch(): + L = Names[:] + found = False + for l in L: + if l == value['linear']: #Check each value + found = True + window.FindElement('display1').Update('Linear search\n' + l + ' found.') + break + if not found: + window.FindElement('display1').Update(value['linear'] + ' was \nNot found') + +#Binary Search - only works for ordered lists +def binarySearch(): + L = SortedNames[:] + lo = 0 + hi = len(L)-1 + found = False #Start with found is Flase + while lo <= hi: + mid = (lo + hi) //2 #Start in middle + if L[mid] == value['binary']: #get the value from the search box + window.FindElement('display2').Update('Binary search\n' + L[mid] + ' found.') + found = True #If found display + break #and stop + elif L[mid] < value['binary']: + lo = mid + 1 #Search in top half + else: + hi = mid - 1 #Search in lower half + if not found: #If we get to end - display not found + window.FindElement('display2').Update(value['binary'] + ' was \nNot found') + +while True: + button, value = window.Read() + if button is not None: + if button == 'Show Names': #show names - unordered and sorted + displayList(Names,'display1') + displayList(SortedNames, 'display2') + if button == 'ls': #Find and display + linearSearch() + if button == 'bs': #Find and display + binarySearch() + else: + break + diff --git a/ProgrammingClassExamples/6c PSG search text preloaded.py b/ProgrammingClassExamples/6c PSG search text preloaded.py new file mode 100644 index 00000000..cbc6832c --- /dev/null +++ b/ProgrammingClassExamples/6c PSG search text preloaded.py @@ -0,0 +1,79 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +import PySimpleGUI as sg + +sg.SetOptions (font =('Calibri',12,'bold')) + +#names for Demo, could be loaded from a file + +Names = ['Roberta', 'Kylie', 'Jenny', 'Helen', + 'Andrea', 'Meredith','Deborah','Pauline', + 'Belinda', 'Wendy'] +names = '' +for l in Names: + names = names + l + '\n' + +SortedNames = ['Andrea','Belinda','Deborah','Helen', + 'Jenny','Kylie','Meredith','Pauline', + 'Roberta','Wendy'] + +sortnames = '' +for l in SortedNames: + sortnames = sortnames + l +'\n' + +layout =[[sg.Text('Search Demo', font =('Calibri', 18, 'bold'))], +[sg.Text(names,size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display1'), + sg.Text(sortnames,size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display2')], + [sg.Text('_'*32,font = ('Calibri', 12))], + [sg.InputText(size = (14,1), key = 'linear'), sg.InputText(size = (14,1), key = 'binary')], + [sg.ReadButton('Linear Search', bind_return_key=True, size = (13,1)), sg.ReadButton('Binary Search', size = (14,1))], + ] +window = sg.Window('Search Demo').Layout(layout) + +#Linear Search - no need for Ordered list +def linearSearch(): + L = Names[:] + found = False + for l in L: + if l == value['linear']: #Check each value + found = True + sg.Popup('Linear search\n' + l + ' found.') + break + if not found: + sg.Popup('Linear search\n' +(value['linear'] + ' was not found')) + +#Binary Search - only works for ordered lists +def binarySearch(): + L = SortedNames[:] + lo = 0 + hi = len(L)-1 + found = False #Start with found is Flase + while lo <= hi: + mid = (lo + hi) //2 #Start in middle + if L[mid] == value['binary']: #get the value from the search box + sg.Popup('Binary search\n' + L[mid] + ' found.') + found = True #If found display + break #and stop + elif L[mid] < value['binary']: + lo = mid + 1 #Search in top half + else: + hi = mid - 1 #Search in lower half + if not found: #If we get to end - display not found + sg.Popup('Binary search\n' +(value['binary'] + ' was not found')) + +while True: + button, value = window.Read() + + if button is not None: + if button == 'Show Names': #show names - unordered and sorted + displayList(Names,'display1') + displayList(SortedNames, 'display2') + if button == 'Linear Search': #Find and display + linearSearch() + if button == 'Binary Search': #Find and display + binarySearch() + else: + break + diff --git a/ProgrammingClassExamples/6d PSG sort and search.py b/ProgrammingClassExamples/6d PSG sort and search.py new file mode 100644 index 00000000..68d84be4 --- /dev/null +++ b/ProgrammingClassExamples/6d PSG sort and search.py @@ -0,0 +1,130 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +import PySimpleGUI as sg + +sg.SetOptions (font =('Calibri',12,'bold')) + + +#setup column (called column1) of buttons to sue in layout + +column1 = [[sg.ReadButton('Original list', size = (13,1))], + [sg.ReadButton('Default sort', size = (13,1))], + [sg.ReadButton('Sort: selection',size = (13,1))], + [sg.ReadButton('Sort: quick', size = (13,1))]] + +layout =[[sg.Text('Search and Sort Demo', font =('Calibri', 20, 'bold'))], +[sg.Text('',size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display'), sg.Column(column1)], + [sg.Text('_'*32,font = ('Calibri', 12))], + [sg.InputText(size = (13,1), key = 'linear'), sg.Text(' '), sg.InputText(size = (13,1), key = 'binary')], + [sg.ReadButton('Linear Search', size = (13,1)), sg.Text(' '), sg.ReadButton('Binary Search', size = (13,1))], + ] + +window = sg.Window('Search and Sort Demo').Layout(layout) + +#names for Demo, could be loaded from a file +Names= ['Roberta', 'Kylie', 'Jenny', 'Helen', + 'Andrea', 'Meredith','Deborah','Pauline', + 'Belinda', 'Wendy'] + +#function to display list +def displayList(List): + global ListDisplayed #store list in Multiline text globally + ListDisplayed = List + display = '' + for l in List: #add list elements with new line + display = display + l + '\n' + window.FindElement('display').Update(display) + +#use inbuilt python sort +def default(Names): + L = Names[:] + L.sort() #inbuilt sort + displayList(L) + +#Selection sort - See Janson Ch 7 +def selSort(Names): + L = Names[:] + for i in range(len(L)): + smallest = i + for j in range(i+1, len(L)): + if L[j] < L[smallest]: #find smallest value + smallest = j #swap it to front + L[smallest], L[i] = L[i], L[smallest] #repeat from next poistion + displayList(L) + +#Quick sort - See Janson Ch 7 +def qsortHolder(Names): + L = Names[:] #pass List, first and last + quick_sort(L, 0, len(L) -1) #Start process + displayList(L) + +def quick_sort(L, first, last): #Quicksort is a partition sort + if first >= last: + return L + pivot = L[first] + low = first + high = last + while low < high: + while L[high] > pivot: + high = high -1 + while L[low] < pivot: + low = low + 1 + if low <= high: + L[high], L[low] = L[low], L[high] + low = low + 1 + high = high -1 + quick_sort(L, first, low -1) #continue splitting - sort small lsist + quick_sort(L, low, last) + +#Linear Search - no need for Ordered list +def linearSearch(): + L = Names[:] + found = False + for l in L: + if l == value['linear']: #Check each value + found = True + window.FindElement('display').Update('Linear search\n' + l + ' found.') + break + if not found: + window.FindElement('display').Update(value['linear'] + ' was \nNot found') + +#Binary Search - only works for ordered lists +def binarySearch(): + L = ListDisplayed[:] #get List currently in multiline display + lo = 0 + hi = len(L)-1 + found = False #Start with found is Flase + while lo <= hi: + mid = (lo + hi) //2 #Start in middle + if L[mid] == value['binary']: #get the value from the search box + window.FindElement('display').Update('Binary search\n' + L[mid] + ' found.') + found = True #If found display + break #and stop + elif L[mid] < value['binary']: + lo = mid + 1 #Search in top half + else: + hi = mid - 1 #Search in lower half + if not found: #If we get to end - display not found + window.FindElement('display').Update(value['binary'] + ' was \nNot found') + + +while True: + button, value = window.Read() + if button is not None: + if button == 'Original list': + displayList(Names) + if button == 'Default sort': + default(Names) + if button == 'Sort: selection': + selSort(Names) + if button == 'Sort: quick': + qsortHolder(Names) + if button == 'Linear Search': + linearSearch() + if button == 'Binary Search': + binarySearch() + else: + break + diff --git a/ProgrammingClassExamples/6e PSG sort and search (listbox) TODO.py b/ProgrammingClassExamples/6e PSG sort and search (listbox) TODO.py new file mode 100644 index 00000000..68d84be4 --- /dev/null +++ b/ProgrammingClassExamples/6e PSG sort and search (listbox) TODO.py @@ -0,0 +1,130 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +import PySimpleGUI as sg + +sg.SetOptions (font =('Calibri',12,'bold')) + + +#setup column (called column1) of buttons to sue in layout + +column1 = [[sg.ReadButton('Original list', size = (13,1))], + [sg.ReadButton('Default sort', size = (13,1))], + [sg.ReadButton('Sort: selection',size = (13,1))], + [sg.ReadButton('Sort: quick', size = (13,1))]] + +layout =[[sg.Text('Search and Sort Demo', font =('Calibri', 20, 'bold'))], +[sg.Text('',size = (14, 11),relief=sg.RELIEF_SOLID,font = ('Calibri', 12), background_color ='White',key = 'display'), sg.Column(column1)], + [sg.Text('_'*32,font = ('Calibri', 12))], + [sg.InputText(size = (13,1), key = 'linear'), sg.Text(' '), sg.InputText(size = (13,1), key = 'binary')], + [sg.ReadButton('Linear Search', size = (13,1)), sg.Text(' '), sg.ReadButton('Binary Search', size = (13,1))], + ] + +window = sg.Window('Search and Sort Demo').Layout(layout) + +#names for Demo, could be loaded from a file +Names= ['Roberta', 'Kylie', 'Jenny', 'Helen', + 'Andrea', 'Meredith','Deborah','Pauline', + 'Belinda', 'Wendy'] + +#function to display list +def displayList(List): + global ListDisplayed #store list in Multiline text globally + ListDisplayed = List + display = '' + for l in List: #add list elements with new line + display = display + l + '\n' + window.FindElement('display').Update(display) + +#use inbuilt python sort +def default(Names): + L = Names[:] + L.sort() #inbuilt sort + displayList(L) + +#Selection sort - See Janson Ch 7 +def selSort(Names): + L = Names[:] + for i in range(len(L)): + smallest = i + for j in range(i+1, len(L)): + if L[j] < L[smallest]: #find smallest value + smallest = j #swap it to front + L[smallest], L[i] = L[i], L[smallest] #repeat from next poistion + displayList(L) + +#Quick sort - See Janson Ch 7 +def qsortHolder(Names): + L = Names[:] #pass List, first and last + quick_sort(L, 0, len(L) -1) #Start process + displayList(L) + +def quick_sort(L, first, last): #Quicksort is a partition sort + if first >= last: + return L + pivot = L[first] + low = first + high = last + while low < high: + while L[high] > pivot: + high = high -1 + while L[low] < pivot: + low = low + 1 + if low <= high: + L[high], L[low] = L[low], L[high] + low = low + 1 + high = high -1 + quick_sort(L, first, low -1) #continue splitting - sort small lsist + quick_sort(L, low, last) + +#Linear Search - no need for Ordered list +def linearSearch(): + L = Names[:] + found = False + for l in L: + if l == value['linear']: #Check each value + found = True + window.FindElement('display').Update('Linear search\n' + l + ' found.') + break + if not found: + window.FindElement('display').Update(value['linear'] + ' was \nNot found') + +#Binary Search - only works for ordered lists +def binarySearch(): + L = ListDisplayed[:] #get List currently in multiline display + lo = 0 + hi = len(L)-1 + found = False #Start with found is Flase + while lo <= hi: + mid = (lo + hi) //2 #Start in middle + if L[mid] == value['binary']: #get the value from the search box + window.FindElement('display').Update('Binary search\n' + L[mid] + ' found.') + found = True #If found display + break #and stop + elif L[mid] < value['binary']: + lo = mid + 1 #Search in top half + else: + hi = mid - 1 #Search in lower half + if not found: #If we get to end - display not found + window.FindElement('display').Update(value['binary'] + ' was \nNot found') + + +while True: + button, value = window.Read() + if button is not None: + if button == 'Original list': + displayList(Names) + if button == 'Default sort': + default(Names) + if button == 'Sort: selection': + selSort(Names) + if button == 'Sort: quick': + qsortHolder(Names) + if button == 'Linear Search': + linearSearch() + if button == 'Binary Search': + binarySearch() + else: + break + diff --git a/ProgrammingClassExamples/7a PSG Text file save and retrieve.py b/ProgrammingClassExamples/7a PSG Text file save and retrieve.py new file mode 100644 index 00000000..eea4bf0f --- /dev/null +++ b/ProgrammingClassExamples/7a PSG Text file save and retrieve.py @@ -0,0 +1,59 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +import PySimpleGUI as sg +import os #to work with windows OS + +sg.ChangeLookAndFeel('GreenTan') +sg.SetOptions(font = ('Calibri', 12, 'bold')) + +layout = [ + [sg.Text('Enter a Name and four Marks')], + [sg.Text('Name:', size =(10,1)), sg.InputText(size = (12,1), key = 'name')], + [sg.Text('Mark1:', size =(10,1)), sg.InputText(size = (6,1), key = 'm1')], + [sg.Text('Mark2:', size =(10,1)), sg.InputText(size = (6,1), key = 'm2')], + [sg.Text('Mark3:', size =(10,1)), sg.InputText(size = (6,1), key = 'm3')], + [sg.Text('Mark4:', size =(10,1)), sg.InputText(size = (6,1), key = 'm4')], + [sg.ReadButton('Save', size = (8,1),key = 'save'), sg.Text('Press to Save to file')], + [sg.ReadButton('Display',size = (8,1), key = 'display'), sg.Text('To retrieve and Display')], + [sg.Multiline(size = (28,4), key = 'multiline')]] + +window = sg.Window('Simple Average Finder').Layout(layout) + + +while True: + button, value = window.Read() #value is a dictionary holding name and marks (4) + if button is not None: + #initialise variables + total = 0.0 + index = '' + Name = value['name'] #get name + dirname, filename = os.path.split(os.path.abspath(__file__)) #get pathname to current file + pathname = dirname + '\\results.txt' #add desired file name for saving to path + + #needs validation and try/catch error checking, will crash if blank or text entry for marks + + if button == 'save': + for i in range (1,5): + index = 'm' + str(i) #create dictionary index m1 ... m4 + total += float(value[index]) + average = total/4 + f = open(pathname, 'w') #open file and save + print (Name, file = f) + print (total, file = f) + print (average, file = f) + f.close() + + #some error checking for missing file needed here + + if button == 'display': + #This loads the file line by line into a list called data. + #the strip() removes whitespaces from beginning and end of each line. + data = [line.strip() for line in open(pathname)] + #create single string to display in multiline object. + string = 'Name: ' + data[0] +'\nTotal: ' + str(data[1]) + '\nAverage: ' + str(data[2]) + window.FindElement('multiline').Update(string) + else: + break + diff --git a/ProgrammingClassExamples/8a PSG Data to plot from csv file.py b/ProgrammingClassExamples/8a PSG Data to plot from csv file.py new file mode 100644 index 00000000..99d3a320 --- /dev/null +++ b/ProgrammingClassExamples/8a PSG Data to plot from csv file.py @@ -0,0 +1,38 @@ +#Matplotlib, pyplt and csv +#Tony Crewe +#Sep 2017 - updated Sep 2018 + +import matplotlib.pyplot as plt +import csv +from matplotlib.ticker import MaxNLocator + + +x=[] +y=[] + +with open('weight 20182.csv', 'r', encoding = 'utf-8-sig') as csvfile: + plots = csv.reader(csvfile) + for data in plots: + var1 = (data[0]) #get heading for x and y axes + var2 = (data[1]) + break + for data in plots: #get values - add to x list and y list + x.append(data[0]) + y.append(float(data[1])) + + +ax = plt.subplot(1,1,1) +ax.set_ylim([82, 96]) +ax.xaxis.set_major_locator(MaxNLocator(10)) +ax.spines['right'].set_color('none') +ax.spines['top'].set_color('none') + +plt.plot(x,y, label = 'data loaded\nfrom csv file') +plt.axhline(y = 85.5, color = 'orange', linestyle = '--', label = 'target') +plt.xlabel(var1) +plt.ylabel(var2) +plt.title('weight loss from\n first quarter 2018') + + +plt.legend() +plt.show() diff --git a/ProgrammingClassExamples/8b PSG Tables and calc from csv file.py b/ProgrammingClassExamples/8b PSG Tables and calc from csv file.py new file mode 100644 index 00000000..442e15f8 --- /dev/null +++ b/ProgrammingClassExamples/8b PSG Tables and calc from csv file.py @@ -0,0 +1,41 @@ +#PySimple examples (v 3.8) +#Tony Crewe +#Sep 2018 + +#Based of Example program from MikeTheWatchGuy +#https://gitlab.com/lotspaih/PySimpleGUI + +import sys +import PySimpleGUI as sg +import csv + +def table_example(): + filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),)) + #populate table with file contents + #Assume we know csv has haeding in row 1 + #assume we know 7 columns of data - relevenat to AFL w/o Pts or % shown + #data will be data[0] = team, data [1] P, data [2] W, data[3] L + #data [4] D, data[5] F, data[6] A + #no error checking or validation used. + + data = [] + header_list = [] + with open(filename, "r") as infile: + reader = csv.reader(infile) + for i in range (1): #get headings + header = next(reader) + data = list(reader) # read everything else into a list of rows + + + col_layout = [[sg.Table(values=data, headings=header, max_col_width=25, + auto_size_columns=True, justification='right', size=(None, len(data)))]] + + canvas_size = (13*10*len(header), 600) # estimate canvas size - 13 pixels per char * 10 char per column * num columns + layout = [[sg.Column(col_layout, size=canvas_size, scrollable=True)],] + + window = sg.Window('Table', grab_anywhere=False).Layout(layout) + b, v = window.Read() + + sys.exit(69) + +table_example() diff --git a/ProgrammingClassExamples/9a Plot Matplotlib numpy pyplot(y=sinx).py b/ProgrammingClassExamples/9a Plot Matplotlib numpy pyplot(y=sinx).py new file mode 100644 index 00000000..792408a7 --- /dev/null +++ b/ProgrammingClassExamples/9a Plot Matplotlib numpy pyplot(y=sinx).py @@ -0,0 +1,22 @@ +#matplotlib, numpy, pyplot +#Tony Crewe +#Sep 2017 - updated Sep 2018 + +import matplotlib.pyplot as plt +import numpy as np + + +fig=plt.figure() +ax = fig.add_subplot(111) +x = np.linspace(-np.pi*2, np.pi*2, 100) +y= np.sin(x) +ax.plot(x,y) + +ax.set_title('sin(x)') + + +plt.show() + + + + diff --git a/ProgrammingClassExamples/9b Plot (axes moved).py b/ProgrammingClassExamples/9b Plot (axes moved).py new file mode 100644 index 00000000..7dfba052 --- /dev/null +++ b/ProgrammingClassExamples/9b Plot (axes moved).py @@ -0,0 +1,27 @@ +#matplotlib, numpy, pyplot +#Tony Crewe +#Sep 2017 - updated Sep 2018import matplotlib.pyplot as plt +import numpy as np +import matplotlib.pyplot as plt + + +fig=plt.figure() +ax = fig.add_subplot(111) +x = np.linspace(-np.pi*2, np.pi*2, 100) +y= np.sin(x) +ax.plot(x,y) + +ax.set_title('sin(x)') +#centre bottom and keft axes to zero + +ax.spines['left'].set_position('zero') +ax.spines['right'].set_color('none') +ax.spines['bottom'].set_position('zero') +ax.spines['top'].set_color('none') + + +plt.show() + + + + diff --git a/ProgrammingClassExamples/9c Plot (axes pi format).py b/ProgrammingClassExamples/9c Plot (axes pi format).py new file mode 100644 index 00000000..75c88237 --- /dev/null +++ b/ProgrammingClassExamples/9c Plot (axes pi format).py @@ -0,0 +1,28 @@ +#Plt using matplylib, plotly and numpy +#Tony Crewe +#Sep 2017 updated Sep 2018 + +import matplotlib.pyplot as plt +import numpy as np +import matplotlib.ticker as ticker + +fig=plt.figure() +ax = fig.add_subplot(111) +x = np.linspace(-np.pi*2, np.pi*2, 100) +y= np.sin(x) +ax.plot(x/np.pi,y) + +ax.set_title('sin(x)') +ax.spines['left'].set_position('zero') +ax.spines['right'].set_color('none') +ax.spines['bottom'].set_position('zero') +ax.spines['top'].set_color('none') + +#Format axes - nicer eh! +ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%g $\pi$')) + +plt.show() + + + +