New imports... switched order so that PyCharm will pick up with Python 3 import first
This commit is contained in:
parent
aeafdfeb19
commit
4548b1dd9b
|
@ -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')
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')],
|
||||
|
|
|
@ -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')],
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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] == '#':
|
||||
if len(hex_input) != 0:
|
||||
if hex_input[0] == '#':
|
||||
color_hex = hex_input.upper()
|
||||
color_name = get_name_from_hex(hex_input)
|
||||
elif drop_down_value is not None:
|
||||
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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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/
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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') ]]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')]]
|
||||
|
|
|
@ -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()],
|
||||
|
|
|
@ -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!
|
||||
|
||||
|
||||
|
|
|
@ -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')]]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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")]]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"),))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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')]]
|
||||
|
||||
|
|
|
@ -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')],
|
||||
|
|
|
@ -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') ]]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
"""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,10 +37,9 @@ 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'
|
||||
else:
|
||||
result = value[0] / value[1]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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()
|
|
@ -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()
|
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue