New imports... switched order so that PyCharm will pick up with Python 3 import first

This commit is contained in:
MikeTheWatchGuy 2018-09-28 14:57:37 -04:00
parent aeafdfeb19
commit 4548b1dd9b
84 changed files with 1071 additions and 265 deletions

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
sg.ChangeLookAndFeel('GreenTan') sg.ChangeLookAndFeel('GreenTan')

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Turn off padding in order to get a really tight looking layout. Turn off padding in order to get a really tight looking layout.

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import winsound import winsound

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Demonstrates using a "tight" layout with a Dark theme. 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 Shows how button states can be controlled by a user application. The program manages the disabled/enabled

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [[sg.T('Calendar Test')], layout = [[sg.T('Calendar Test')],
[sg.In('', size=(20,1), key='input')], [sg.In('', size=(20,1), key='input')],

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [ layout = [
[sg.Canvas(size=(150, 150), background_color='red', key='canvas')], [sg.Canvas(size=(150, 150), background_color='red', key='canvas')],

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg 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 A chat window. Add call to your send-routine, print the response and you're done

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
''' '''
A chatbot with history A chatbot with history
Scroll up and down through prior commands using the arrow keys Scroll up and down through prior commands using the arrow keys

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
from chatterbot import ChatBot from chatterbot import ChatBot
import chatterbot.utils import chatterbot.utils

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
MY_WINDOW_ICON = 'E:\\TheRealMyDocs\\Icons\\The Planets\\jupiter.ico' MY_WINDOW_ICON = 'E:\\TheRealMyDocs\\Icons\\The Planets\\jupiter.ico'
reverse = {} reverse = {}
@ -1702,10 +1702,14 @@ def main():
if hex_input == '' and len(drop_down_value) == 0: if hex_input == '' and len(drop_down_value) == 0:
continue continue
if hex_input is not '' and hex_input[0] == '#': if len(hex_input) != 0:
color_hex = hex_input.upper() if hex_input[0] == '#':
color_name = get_name_from_hex(hex_input) color_hex = hex_input.upper()
elif drop_down_value is not None: 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_name = drop_down_value[0]
color_hex = get_hex_from_name(color_name) color_hex = get_hex_from_name(color_name)

View File

@ -1,9 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Shows a big chart of colors... give it a few seconds to create it Shows a big chart of colors... give it a few seconds to create it

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Color names courtesy of Big Daddy's Wiki-Python Color names courtesy of Big Daddy's Wiki-Python
http://www.wikipython.com/tkinter-ttk-tix/summary-information/colors/ http://www.wikipython.com/tkinter-ttk-tix/summary-information/colors/

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
sg.ChangeLookAndFeel('BlueMono') sg.ChangeLookAndFeel('BlueMono')

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
# sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT) # sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT)
def GetFilesToCompare(): def GetFilesToCompare():

View File

@ -31,7 +31,11 @@ pixmaps and page re-visits will re-use a once-created display list.
""" """
import sys import sys
import fitz 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 import tkinter as tk
from PIL import Image, ImageTk from PIL import Image, ImageTk
import time import time

View File

@ -9,7 +9,11 @@ These are the accepted design patterns that cover the two primary use cases
# ---------------------------------# # ---------------------------------#
# DESIGN PATTERN 1 - Simple Window # # 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') ]] layout = [[ sg.Text('My layout') ]]
@ -20,7 +24,11 @@ button, value = window.Read()
# -------------------------------------# # -------------------------------------#
# DESIGN PATTERN 2 - Persistent Window # # 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') ]] layout = [[ sg.Text('My layout') ]]
@ -34,7 +42,11 @@ while True: # Event Loop
# ------------------------------------------------------------------# # ------------------------------------------------------------------#
# DESIGN PATTERN 3 - Persistent Window with "early update" required # # 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') ]] layout = [[ sg.Text('My layout') ]]

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import subprocess import subprocess
import os import os

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: import sys
import PySimpleGUI27 as sg if sys.version_info[0] >= 3:
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import time import time
import random import random
import psutil import psutil

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: import sys
import PySimpleGUI27 as sg if sys.version_info[0] >= 3:
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import psutil import psutil
import time import time
from threading import Thread from threading import Thread

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: import sys
import PySimpleGUI27 as sg if sys.version_info[0] >= 3:
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import psutil import psutil

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: import sys
import PySimpleGUI27 as sg if sys.version_info[0] >= 3:
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import time import time
""" """
@ -22,7 +23,7 @@ layout = [[sg.Text('')],
sg.ReadButton('Reset', button_color=('white', '#007339'), key='Reset'), sg.ReadButton('Reset', button_color=('white', '#007339'), key='Reset'),
sg.Exit(button_color=('white', 'firebrick4'), key='Exit')]] 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 ---------------- # ---------------- main loop ----------------
current_time = 0 current_time = 0

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: import sys
import PySimpleGUI27 as sg if sys.version_info[0] >= 3:
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
sg.ChangeLookAndFeel('Dark') sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0, 0)) sg.SetOptions(element_padding=(0, 0))

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: import sys
import PySimpleGUI27 as sg if sys.version_info[0] >= 3:
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import hashlib import hashlib
import os import os

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: import sys
import PySimpleGUI27 as sg if sys.version_info[0] >= 3:
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
def Everything(): def Everything():
sg.ChangeLookAndFeel('TanBlue') sg.ChangeLookAndFeel('TanBlue')

View File

@ -1,8 +1,12 @@
# Testing async form, see if can have a slider # Testing async form, see if can have a slider
# that adjusts the size of text displayed # 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 fontSize = 12
layout = [[sg.Spin([sz for sz in range(6, 172)], font=('Helvetica 20'), initial_value=fontSize, change_submits=True, key='spin'), 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')]] 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')]]

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [[sg.Text('Filename', )], layout = [[sg.Text('Filename', )],
[sg.Input(), sg.FileBrowse()], [sg.Input(), sg.FileBrowse()],

View File

@ -1,53 +1,52 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
import time else:
import PySimpleGUI27 as sg
def main(): def main():
# ------- Make a new Window ------- # # ------- Make a new Window ------- #
window = gg.Window('GoodColors', auto_size_text=True, default_element_size=(30,2)) window = sg.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(sg.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.AddRow(sg.Text('Here come the good colors as defined by PySimpleGUI'))
#===== Show some nice BLUE colors with yellow text ===== ===== ===== ===== ===== ===== =====# #===== Show some nice BLUE colors with yellow text ===== ===== ===== ===== ===== ===== =====#
text_color = gg.YELLOWS[0] text_color = sg.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)) 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(gg.T('Button Colors Using PySimpleGUI.BLUES')) window.AddRow(sg.T('Button Colors Using PySimpleGUI.BLUES'))
window.AddRow(*buttons) 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 ===== ===== ===== ===== ===== ===== =====# #===== 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)) 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(gg.T('Button Colors Using PySimpleGUI.PURPLES')) window.AddRow(sg.T('Button Colors Using PySimpleGUI.PURPLES'))
window.AddRow(*buttons) 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 ===== ===== ===== ===== ===== ===== =====# #===== 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)) 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(gg.T('Button Colors Using PySimpleGUI.GREENS')) window.AddRow(sg.T('Button Colors Using PySimpleGUI.GREENS'))
window.AddRow(*buttons) 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 ===== ===== ===== ===== ===== ===== =====# #===== Show some nice TAN colors with yellow text ===== ===== ===== ===== ===== ===== =====#
text_color = gg.GREENS[0] # let's use GREEN text on the tan text_color = sg.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)) 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(gg.T('Button Colors Using PySimpleGUI.TANS')) window.AddRow(sg.T('Button Colors Using PySimpleGUI.TANS'))
window.AddRow(*buttons) 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 ===== ===== ===== ===== ===== ===== =====# #===== Show some nice YELLOWS colors with black text ===== ===== ===== ===== ===== ===== =====#
text_color = 'black' # let's use black text on the tan 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)) 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(gg.T('Button Colors Using PySimpleGUI.YELLOWS')) window.AddRow(sg.T('Button Colors Using PySimpleGUI.YELLOWS'))
window.AddRow(*buttons) 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 ===== ===== ===== ===== ===== ===== =====# #===== 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! (button, value) = window.Show() # show it!

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg 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')], 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')]] [sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue'), sg.ReadButton('Move')]]

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import ping import ping
from threading import Thread from threading import Thread
import time import time

View File

@ -1,16 +1,20 @@
#!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import math import math
layout = [[sg.T('Example of Using Math with a Graph', justification='center',
layout = [[sg.T('Example of Using Math with a Graph', justification='center', size=(40,1), relief=sg.RELIEF_RAISED)], 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', tooltip='This is a cool graph!')],] [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() window = sg.Window('Graph of Sine Function', grab_anywhere=True).Layout(layout).Finalize()
graph = window.FindElement('graph') graph = window.FindElement('graph')
# Draw axis # Draw axis
@ -27,6 +31,7 @@ for y in range(-100, 101, 20):
if y != 0: if y != 0:
graph.DrawText( y, (-10,y), color='blue') graph.DrawText( y, (-10,y), color='blue')
# Draw Graph # Draw Graph
for x in range(-100,100): for x in range(-100,100):
y = math.sin(x/20)*50 y = math.sin(x/20)*50

View File

@ -1,11 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] >= 3:
if sys.version_info[0] < 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
import time else:
import PySimpleGUI27 as sg
import random import random
import sys import sys
@ -47,6 +46,7 @@ def main():
while True: while True:
# time.sleep(.2) # time.sleep(.2)
button, values = window.ReadNonBlocking() button, values = window.ReadNonBlocking()
print(button, values)
if button == 'Quit' or values is None: if button == 'Quit' or values is None:
break break
graph_offset = random.randint(-10, 10) graph_offset = random.randint(-10, 10)

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import subprocess import subprocess

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import os import os
from PIL import Image, ImageTk from PIL import Image, ImageTk
import io import io

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
# Recipe for getting keys, one at a time as they are released # 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" # If want to use the space bar, then be sure and disable the "default focus"

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [[sg.Text("Hold down a key")], layout = [[sg.Text("Hold down a key")],
[sg.Button("OK")]] [sg.Button("OK")]]

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
# Demonstrates a number of PySimpleGUI features including: # Demonstrates a number of PySimpleGUI features including:
# Default element size # Default element size

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import os import os
import mido import mido
import time import time

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
def MachineLearningGUI(): def MachineLearningGUI():
sg.SetOptions(text_justification='right') sg.SetOptions(text_justification='right')

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import matplotlib import matplotlib
matplotlib.use('TkAgg') 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 figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
# define the form layout # 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.Canvas(size=(figure_w, figure_h), key='canvas')],
[sg.OK(pad=((figure_w / 2, 0), 3), size=(4, 2))]] [sg.OK(pad=((figure_w / 2, 0), 3), size=(4, 2))]]
# create the form and show it without the plot # 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 # add the plot to the window
fig_photo = draw_figure(window.FindElement('canvas').TKCanvas, fig) fig_photo = draw_figure(window.FindElement('canvas').TKCanvas, fig)

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
from random import randint from random import randint
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg
from matplotlib.figure import Figure from matplotlib.figure import Figure

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
from random import randint from random import randint
import PySimpleGUI as sg import PySimpleGUI as sg
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import matplotlib import matplotlib
matplotlib.use('TkAgg') matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasAgg from matplotlib.backends.backend_tkagg import FigureCanvasAgg

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasAgg from matplotlib.backends.backend_tkagg import FigureCanvasAgg
import matplotlib.backends.tkagg as tkagg import matplotlib.backends.tkagg as tkagg

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import ping import ping
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, FigureCanvasAgg

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
# #
# An Async Demonstration of a media player # An Async Demonstration of a media player

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Demonstration of MENUS! Demonstration of MENUS!
How do menus work? Like buttons is how. How do menus work? Like buttons is how.
@ -27,13 +26,13 @@ def TestMenus():
sg.SetOptions(element_padding=(0, 0)) sg.SetOptions(element_padding=(0, 0))
# ------ Menu Definition ------ # # ------ Menu Definition ------ #
menu_def = [['File', ['Open', 'Save', 'Properties']], menu_def = [['File', ['O_&pen', 'Save', '---', 'Properties']],
['Edit', ['Paste', ['Special', 'Normal',], 'Undo'],], ['Edit', ['Paste', ['Special', 'Normal',], 'Undo'],],
['Help', 'About...'],] ['Help', 'About...'],]
# ------ GUI Defintion ------ # # ------ GUI Defintion ------ #
layout = [ layout = [
[sg.Menu(menu_def, tearoff=True)], [sg.Menu(menu_def, tearoff=False)],
[sg.Output(size=(60,20))], [sg.Output(size=(60,20))],
[sg.In('Test', key='input', do_not_clear=True)] [sg.In('Test', key='input', do_not_clear=True)]
] ]
@ -49,7 +48,9 @@ def TestMenus():
print('Button = ', button) print('Button = ', button)
# ------ Process menu choices ------ # # ------ Process menu choices ------ #
if button == 'About...': if button == 'About...':
window.Disable()
sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...') sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...')
window.Enable()
elif button == 'Open': elif button == 'Open':
filename = sg.PopupGetFile('file to open', no_window=True) filename = sg.PopupGetFile('file to open', no_window=True)
print(filename) print(filename)

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import time import time
# Window that doen't block # Window that doen't block

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import cv2 as cv import cv2 as cv
from PIL import Image from PIL import Image
import tempfile import tempfile

View File

@ -34,7 +34,10 @@ pixmaps and page re-visits will re-use a once-created display list.
""" """
import sys import sys
import fitz 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 sys import exit as exit
from binascii import hexlify from binascii import hexlify

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import os import os
from sys import exit as exit from sys import exit as exit

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import hashlib import hashlib
from sys import exit as exit from sys import exit as exit

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
# GUI for switching an LED on and off to GPIO14 # GUI for switching an LED on and off to GPIO14
# GPIO and time library: # GPIO and time library:
@ -32,13 +32,13 @@ def FlashLED():
GPIO.output(14, GPIO.LOW) GPIO.output(14, GPIO.LOW)
time.sleep(0.5) time.sleep(0.5)
layout = [[rg.T('Raspberry Pi LEDs')], layout = [[sg.T('Raspberry Pi LEDs')],
[rg.T('', size=(14, 1), key='output')], [sg.T('', size=(14, 1), key='output')],
[rg.ReadButton('Switch LED')], [sg.ReadButton('Switch LED')],
[rg.ReadButton('Flash LED')], [sg.ReadButton('Flash LED')],
[rg.Exit()]] [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: while True:
button, values = window.Read() button, values = window.Read()
@ -53,4 +53,4 @@ while True:
FlashLED() FlashLED()
window.FindElement('output').Update('') window.FindElement('output').Update('')
rg.Popup('Done... exiting') sg.Popup('Done... exiting')

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
# Robotics design pattern # Robotics design pattern
# Uses Realtime Buttons to simulate the controls for a robot # Uses Realtime Buttons to simulate the controls for a robot

View File

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
from threading import Thread from threading import Thread
import time import time
from sys import exit as exit from sys import exit as exit

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import random import random
import time import time
from sys import exit as exit from sys import exit as exit

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
# Here, have some windows on me.... # Here, have some windows on me....
[sg.PopupNoWait(location=(10*x,0)) for x in range(10)] [sg.PopupNoWait(location=(10*x,0)) for x in range(10)]

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
from time import sleep from time import sleep
from sys import exit as exit from sys import exit as exit

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import glob import glob
import ntpath import ntpath
import subprocess import subprocess

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
import sys else:
import PySimpleGUI27 as sg
''' '''
Quickly add a GUI to your script! Quickly add a GUI to your script!

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Demo of how to combine elements into your own custom element Demo of how to combine elements into your own custom element
""" """

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Simple Form showing how to use keys on your input fields Simple Form showing how to use keys on your input fields

View File

@ -1,11 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import csv import csv
import sys
def table_example(): def table_example():
filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),)) filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),))

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import csv import csv

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import pandas as pd import pandas as pd

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import csv import csv

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
tab1_layout = [[sg.T('This is inside tab 1')]] tab1_layout = [[sg.T('This is inside tab 1')]]

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
sg.ChangeLookAndFeel('GreenTan') sg.ChangeLookAndFeel('GreenTan')
tab2_layout = [[sg.T('This is inside tab 2')], tab2_layout = [[sg.T('This is inside tab 2')],

View File

@ -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 # # DESIGN PATTERN 1 - Simple Window #
# ---------------------------------# # ---------------------------------#
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [[ sg.Text('My layout') ]] layout = [[ sg.Text('My layout') ]]
@ -21,10 +21,10 @@ button, value = window.Read()
# -------------------------------------# # -------------------------------------#
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
layout = [[ sg.Text('My layout') ]] layout = [[ sg.Text('My layout') ]]

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] < 3: if sys.version_info[0] >= 3:
import PySimpleGUI27 as sg
else:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import subprocess import subprocess
""" """

View File

@ -16,7 +16,7 @@ sg.SetOptions (background_color = 'LightBlue',
#adjust widths #adjust widths
layout = [ layout = [
[sg.Text('Celcius', size =(12,1)), sg.InputText(size = (8,1))], [sg.Text('Celcius', size =(12,1)), sg.InputText(size = (8,1))],
[sg.Submit()], [sg.Submit()]
] ]
window = sg.Window('Converter').Layout(layout) window = sg.Window('Converter').Layout(layout)

View File

@ -4,6 +4,8 @@
import PySimpleGUI as sg import PySimpleGUI as sg
#use of Column to help with layout - vertical sliders take up space
column1 = [ column1 = [
[sg.Text('Pick operation', size = (15,1), font = ('Calibri', 12, 'bold'))], [sg.Text('Pick operation', size = (15,1), font = ('Calibri', 12, 'bold'))],
[sg.InputCombo(['Add','Subtract','Multiply','Divide'], size = (10,6))], [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.Slider(range = (-9, 9),orientation = 'v', size = (5, 20), default_value = 0),
sg.Text(' '), sg.Column(column1), sg.Column(column2)]] 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: while True:
button, value = window.Read() button, value = window.Read()
if button is not None: if button is not None:
@ -31,11 +37,10 @@ while True:
result = value[0] * value[1] result = value[0] * value[1]
elif value[2] == 'Subtract': elif value[2] == 'Subtract':
result = value[0] - value[1] result = value[0] - value[1]
elif value[2] == 'Divide': elif value[2] == 'Divide': #check for zero
if value[1] ==0: if value[1] ==0:
sg.Popup('Second value can\'t be zero') sg.Popup('Second value can\'t be zero')
if value[0] == 0: result = 'NA'
result = 'NA'
else: else:
result = value[0] / value[1] result = value[0] / value[1]
window.FindElement('result').Update(result) window.FindElement('result').Update(result)

View File

@ -7,19 +7,20 @@ sg.SetOptions(font= ('Calibri', 12, 'bold'))
layout = [ layout = [
[sg.Text('Spinner and Combo box demo', font = ('Calibri', 14, 'bold'))], [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)], size = (2,1),initial_value = 0),
sg.Spin([sz for sz in range (-9,10)], initial_value = 0), sg.Spin([sz for sz in range (-9,10)], size = (2,1), initial_value = 0),
sg.Text('Pick operation', size = (13,1)), sg.Text('Pick operation ->', size = (15,1)),
sg.InputCombo(['Add','Subtract','Multiply','Divide'], size = (8,6))], 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'))]] 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: while True:
button, value = window.Read() button, value = window.Read()
if button is not None: if button is not None:
#convert returned values to integers
val = [int(value[0]), int(value[1])] val = [int(value[0]), int(value[1])]
if value[2] == 'Add': if value[2] == 'Add':
result = val[0] + val[1] result = val[0] + val[1]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()