def Launcher2(): sg.ChangeLookAndFeel('GreenTan') window = sg.Window('Script launcher') filelist = glob.glob(LOCATION_OF_YOUR_SCRIPTS + '*.py') namesonly = [] for file in filelist: namesonly.append(ntpath.basename(file)) layout = [ [ sg.Listbox(values=namesonly, size=(30, 19), select_mode=sg.SELECT_MODE_EXTENDED, key='demolist'), sg.Output(size=(88, 20), font='Courier 10') ], [ sg.Checkbox('Wait for program to complete', default=False, key='wait') ], [ sg.ReadButton('Run'), sg.ReadButton('Shortcut 1'), sg.ReadButton('Fav Program'), sg.Button('EXIT') ], ] window.Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # while True: (button, value) = window.Read() if button in ('EXIT', None): break # exit button clicked if button in ('Shortcut 1', 'Fav Program'): print( 'Quickly launch your favorite programs using these shortcuts') print( 'Or copy files to your github folder. Or anything else you type on the command line' ) # copyfile(source, dest) elif button is 'Run': for index, file in enumerate(value['demolist']): print('Launching %s' % file) window.Refresh() # make the print appear immediately if value['wait']: execute_command_blocking(LOCATION_OF_YOUR_SCRIPTS + file) else: execute_command_nonblocking(LOCATION_OF_YOUR_SCRIPTS + file)
def start_app(): layout = [[ sg.Text('Enter the last four of your phone number', size=(75, 1), justification='center', font=("Helvetica", 18)) ], [ sg.Text('', size=(35, 1)), sg.InputText(font=("Helvetica", 18), justification='center', size=(30, 1), key='input_box') ], [ sg.Text('', size=(35, 1)), sg.ReadButton('Submit'), sg.Text('', size=(18, 1)), sg.ReadButton('Clear') ], [sg.Exit(key='Exit')]] window = sg.Window('Log In/Out', auto_size_buttons=False, return_keyboard_events=True).Layout(layout) while True: button, values = window.Read() if button == 'Exit' or values is None: break elif button == 'Clear': element = window.FindElement('input_box') element.Update('') elif button == 'Submit' or ord(str(button)) == 13: phone_number = values['input_box'] try: int(phone_number) if int(phone_number) > 9999: sg.Popup('Enter last four of your phone number.') elif len(phone_number) < 4: sg.Popup('Enter last four of your phone number.') else: failed = fetch_user(phone_number) if failed: sg.Popup('Invalid phone number.') element = window.FindElement('input_box') element.Update('') except: sg.Popup('Number values only.') element = window.FindElement('input_box') element.Update('')
def creategui(): sg.ChangeLookAndFeel('BlueMono') frame_layout = [ [sg.T('Elapsed', size=(60, 1), key='-ELAPSED-')], [sg.Multiline('', size=(60, 12), autoscroll=True, key='-ML-')], ] # define the window layout layout = [[ sg.Text('OMRON HVC P2 Demo GUI', size=(50, 1), justification='center', font='Helvetica 20') ], [sg.Image(filename='', key='image'), sg.Frame('Result', frame_layout)], [ sg.ReadButton('Exit', size=(10, 1), pad=((0, 0), 3), font='Helvetica 14'), sg.RButton('Pause', key='-RUN-PAUSE-', size=(10, 1), font='Any 14') ]] # create the window and show it without the plot window = sg.Window('OMRON HVC P2 Demo Application', location=(400, 200)) #window.Layout(layout).Finalize() window.Layout(layout) return window
def main(): global g_my_globals # define the form layout layout = [[ sg.Canvas(size=SIZE, background_color='white', key='canvas'), sg.ReadButton('Exit', pad=(0, (210, 0))) ]] # create the form and show it without the plot window = sg.Window('Ping Graph', background_color='white', grab_anywhere=True).Layout(layout).Finalize() canvas_elem = window.FindElement('canvas') canvas = canvas_elem.TKCanvas fig = plt.figure(figsize=(3.1, 2.25), tight_layout={'pad': 0}) g_my_globals.axis_ping = fig.add_subplot(1, 1, 1) plt.rcParams['xtick.labelsize'] = 8 plt.rcParams['ytick.labelsize'] = 8 set_chart_labels() plt.tight_layout() while True: button, values = window.ReadNonBlocking() if button is 'Exit' or values is None: exit(0) run_a_ping_and_graph() photo = draw(fig, canvas)
def main(): # filename = 'C:/Python/MIDIVideo/PlainVideos/- 08-30 Ted Talk/TED Talk Short - Video+.mp4' filename = sg.PopupGetFile('Filename to play') if filename is None: exit(69) vidFile = cv.VideoCapture(filename) # ---===--- Get some Stats --- # num_frames = vidFile.get(cv.CAP_PROP_FRAME_COUNT) fps = vidFile.get(cv.CAP_PROP_FPS) sg.ChangeLookAndFeel('Dark') # define the window layout layout = [[ sg.Text('OpenCV Demo', size=(15, 1), pad=((510, 0), 3), justification='center', font='Helvetica 20') ], [sg.Image(filename='', key='image')], [ sg.Slider(range=(0, num_frames), size=(115, 10), orientation='h', key='slider') ], [ sg.ReadButton('Exit', size=(10, 2), pad=((600, 0), 3), font='Helvetica 14') ]] # create the window and show it without the plot window = sg.Window('Demo Application - OpenCV Integration', no_titlebar=False, location=(0, 0)) window.Layout(layout) window.ReadNonBlocking() # ---===--- LOOP through video file by frame --- # i = 0 temp_filename = next(tempfile._get_candidate_names()) + '.png' while vidFile.isOpened(): button, values = window.ReadNonBlocking() if button is 'Exit' or values is None: os.remove(temp_filename) exit(69) ret, frame = vidFile.read() if not ret: # if out of data stop looping break window.FindElement('slider').Update(i) i += 1 with open(temp_filename, 'wb') as f: Image.fromarray(frame).save(temp_filename, 'PNG') # save the PIL image as file window.FindElement('image').Update(filename=temp_filename)
def StatusOutputExample(): # Create a text element that will be updated with status information on the GUI itself # Create the rows layout = [[sg.Text('Non-blocking GUI with updates')], [ sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='output') ], [ sg.ReadButton('LED On'), sg.ReadButton('LED Off'), sg.ReadButton('Quit') ]] # Layout the rows of the Window and perform a read. Indicate the Window is non-blocking! window = sg.Window('Running Timer', auto_size_text=True).Layout(layout) # # Some place later in your code... # You need to perform a ReadNonBlocking on your window every now and then or # else it won't refresh. # # your program's main loop i = 0 while (True): # This is the code that reads and updates your window button, values = window.ReadNonBlocking() window.FindElement('output').Update('{:02d}:{:02d}.{:02d}'.format( (i // 100) // 60, (i // 100) % 60, i % 100)) if button == 'Quit' or values is None: break if button == 'LED On': print('Turning on the LED') elif button == 'LED Off': print('Turning off the LED') i += 1 # Your code begins here time.sleep(.01) # Broke out of main loop. Close the window. window.CloseNonBlocking()
def ChatBotWithHistory(): # ------- Make a new Window ------- # sg.ChangeLookAndFeel('GreenTan') # give our form a spiffy set of colors layout = [[sg.Text('Your output will go here', size=(40, 1))], [sg.Output(size=(127, 30), font=('Helvetica 10'))], [sg.T('Command History'), sg.T('', size=(20, 3), key='history')], [ sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False), sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0])) ]] window = sg.Window('Chat window with history', default_element_size=(30, 2), font=('Helvetica', ' 13'), default_button_element_size=(8, 2), return_keyboard_events=True).Layout(layout) # ---===--- Loop taking in user input and using it --- # command_history = [] history_offset = 0 while True: (button, value) = window.Read() if button is 'SEND': query = value['query'].rstrip() # EXECUTE YOUR COMMAND HERE print('The command you entered was {}'.format(query)) command_history.append(query) history_offset = len(command_history) - 1 window.FindElement('query').Update( '' ) # manually clear input because keyboard events blocks clear window.FindElement('history').Update('\n'.join( command_history[-3:])) elif button is None or button is 'EXIT': # quit if exit button or X break elif 'Up' in button and len(command_history): command = command_history[history_offset] history_offset -= 1 * (history_offset > 0) # decrement is not zero window.FindElement('query').Update(command) elif 'Down' in button and len(command_history): history_offset += 1 * (history_offset < len(command_history) - 1 ) # increment up to end of list command = command_history[history_offset] window.FindElement('query').Update(command) elif 'Escape' in button: window.FindElement('query').Update('') sys.exit(69)
def DownloadSubtitlesGUI(): sg.ChangeLookAndFeel('Dark') combobox = sg.InputCombo(values=['',], size=(10,1), key='lang') layout = [ [sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))], [sg.T('YouTube Link'),sg.In(default_text='',size=(60,1), key='link', do_not_clear=True) ], [sg.Output(size=(90,20), font='Courier 12')], [sg.ReadButton('Get List')], [sg.T('Language Code'), combobox, sg.ReadButton('Download')], [sg.Button('Exit', button_color=('white', 'firebrick3'))] ] window = sg.Window('Subtitle Grabber launcher', text_justification='r', default_element_size=(15,1), font=('Any 14')).Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # while True: (button, gui) = window.Read() if button in ('EXIT', None): break # exit button clicked link = gui['link'] if button is 'Get List': print('Getting list of subtitles....') window.Refresh() command = [f'C:/Python/PycharmProjects/GooeyGUI/youtube-dl --list-subs {link}',] output = ExecuteCommandSubprocess(command, wait=True, quiet=True) lang_list = [o[:5].rstrip() for o in output.split('\n') if 'vtt' in o] lang_list = sorted(lang_list) combobox.Update(values=lang_list) print('Done') elif button is 'Download': lang = gui['lang'] if lang is '': lang = 'en' print(f'Downloading subtitle for {lang}...') window.Refresh() command = (f'C:/Python/PycharmProjects/GooeyGUI/youtube-dl --sub-lang {lang} --write-sub {link}',) ExecuteCommandSubprocess(command, wait=True) print('Done')
def Launcher(): # def print(line): # window.FindElement('output').Update(line) sg.ChangeLookAndFeel('Dark') namesonly = [f for f in os.listdir(ROOT_PATH) if f.endswith('.py')] sg.SetOptions(element_padding=(0, 0), button_element_size=(12, 1), auto_size_buttons=False) layout = [[ sg.Combo(values=namesonly, size=(35, 30), key='demofile'), sg.ReadButton('Run', button_color=('white', '#00168B')), sg.ReadButton('Program 1'), sg.ReadButton('Program 2'), sg.ReadButton('Program 3', button_color=('white', '#35008B')), sg.Button('EXIT', button_color=('white', 'firebrick3')) ], [sg.T('', text_color='white', size=(50, 1), key='output')]] window = sg.Window('Floating Toolbar', no_titlebar=True, keep_on_top=True).Layout(layout) # ---===--- Loop taking in user input and executing appropriate program --- # while True: (button, value) = window.Read() if button is 'EXIT' or button is None: break # exit button clicked if button is 'Program 1': print('Run your program 1 here!') elif button is 'Program 2': print('Run your program 2 here!') elif button is 'Run': file = value['demofile'] print('Launching %s' % file) ExecuteCommandSubprocess('python', os.path.join(ROOT_PATH, file)) else: print(button)
def pong(): # ------------- Define GUI layout ------------- layout = [[ sg.Canvas(size=(700, 400), background_color='black', key='canvas') ], [sg.T(''), sg.ReadButton('Quit')]] # ------------- Create window ------------- window = sg.Window('The Classic Game of Pong', return_keyboard_events=True).Layout(layout).Finalize() # window.Finalize() # TODO Replace with call to window.Finalize once code released # ------------- Get the tkinter Canvas we're drawing on ------------- canvas = window.FindElement('canvas').TKCanvas # ------------- Create line down center, the bats and ball ------------- canvas.create_line(350, 0, 350, 400, fill='white') bat1 = pongbat(canvas, 'white') bat2 = pongbat2(canvas, 'white') ball1 = Ball(canvas, bat1, bat2, 'green') # ------------- Event Loop ------------- while True: # ------------- Draw ball and bats ------------- ball1.draw() bat1.draw() bat2.draw() # ------------- Read the form, get keypresses ------------- button, values = window.ReadNonBlocking() # ------------- If quit ------------- if button is None and values is None or button == 'Quit': exit(69) # ------------- Keypresses ------------- if button is not None: if button.startswith('Up'): bat2.up(2) elif button.startswith('Down'): bat2.down(2) elif button == 'w': bat1.up(1) elif button == 's': bat1.down(1) if ball1.checkwin(): sg.Popup('Game Over', ball1.checkwin() + ' won!!') break # ------------- Bottom of loop, delay between animations ------------- # time.sleep(.01) canvas.after(10)
def HowDoI(): ''' Make and show a window (PySimpleGUI form) that takes user input and sends to the HowDoI web oracle Excellent example of 2 GUI concepts 1. Output Element that will show text in a scrolled window 2. Non-Window-Closing Buttons - These buttons will cause the form to return with the form's values, but doesn't close the form :return: never returns ''' # ------- Make a new Window ------- # sg.ChangeLookAndFeel('GreenTan') # give our form a spiffy set of colors layout = [ [sg.Text('Ask and your answer will appear here....', size=(40, 1))], [sg.Output(size=(127, 30), font=('Helvetica 10'))], [ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='Num Answers', font='Helvetica 15'), sg.Text('Num Answers',font='Helvetica 15'), sg.Checkbox('Display Full Text', key='full text', font='Helvetica 15'), sg.T('Command History', font='Helvetica 15'), sg.T('', size=(40,3), text_color=sg.BLUES[0], key='history')], [sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False), sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))] ] window = sg.Window('How Do I ??', default_element_size=(30, 2), icon=DEFAULT_ICON, font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True, no_titlebar=True, grab_anywhere=True) window.Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # command_history = [] history_offset = 0 while True: (button, value) = window.Read() if button is 'SEND': query = value['query'].rstrip() print(query) QueryHowDoI(query, value['Num Answers'], value['full text']) # send the string to HowDoI command_history.append(query) history_offset = len(command_history)-1 window.FindElement('query').Update('') # manually clear input because keyboard events blocks clear window.FindElement('history').Update('\n'.join(command_history[-3:])) elif button is None or button is 'EXIT': # if exit button or closed using X break elif 'Up' in button and len(command_history): # scroll back in history command = command_history[history_offset] history_offset -= 1 * (history_offset > 0) # decrement is not zero window.FindElement('query').Update(command) elif 'Down' in button and len(command_history): # scroll forward in history history_offset += 1 * (history_offset < len(command_history)-1) # increment up to end of list command = command_history[history_offset] window.FindElement('query').Update(command) elif 'Escape' in button: # clear currently line window.FindElement('query').Update('')
def main(): global g_my_globals # define the form layout layout = [[ sg.Text('Animated Ping', size=(40, 1), justification='center', font='Helvetica 20') ], [sg.Canvas(size=(640, 480), key='canvas')], [ sg.ReadButton('Exit', size=(10, 2), pad=((280, 0), 3), font='Helvetica 14') ]] # create the form and show it without the plot window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI' ).Layout(layout).Finalize() canvas_elem = window.FindElement('canvas') canvas = canvas_elem.TKCanvas fig = plt.figure() g_my_globals.axis_ping = fig.add_subplot(1, 1, 1) set_chart_labels() plt.tight_layout() while True: button, values = window.ReadNonBlocking() if button is 'Exit' or values is None: break run_a_ping_and_graph() photo = draw(fig, canvas)
import sys if sys.version_info[0] < 3: import PySimpleGUI27 as sg else: import PySimpleGUI 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') ]] window = sg.Window('Graph test').Layout(layout).Finalize() graph = window.FindElement('graph') circle = graph.DrawCircle((75, 75), 25, fill_color='black', line_color='white') point = graph.DrawPoint((75, 75), 10, color='green') oval = graph.DrawOval((25, 300), (100, 280), fill_color='purple', line_color='purple') rectangle = graph.DrawRectangle((25, 300), (100, 280), line_color='purple') line = graph.DrawLine((0, 0), (100, 100))
sg.T('User:'******'User 1', 'User 2'), size=(20, 1)), sg.T('0', size=(8, 1)) ], [ sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)), sg.T('1', size=(8, 1)) ], [ sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black') ], [ sg.ReadButton('Start', button_color=('white', 'black'), key='Start'), sg.ReadButton('Stop', button_color=('white', 'black'), key='Stop'), sg.ReadButton('Reset', button_color=('white', 'firebrick3'), key='Reset'), sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='Submit') ]] window = sg.Window("Time Tracker", default_element_size=(12, 1), text_justification='r',
russian_trans = translator.translate(noemoji, dest='ru').text english_trans = translator.translate(noemoji, dest='en').text layout = [[sg.Text("User ID: " + name, font=("Calibri", 11))], [ sg.Text("User Geolocation: " + profile_geolocation, font=("Calibri", 11)) ], [ sg.Text("Tweet Geolocation: " + tweet_geolocation, font=("Calibri", 11)) ], [sg.Text("Tweet:\n" + noemoji, font=("Calibri", 11))], [sg.Text(russian_trans, font=("Calibri", 11))], [sg.Text(english_trans, font=("Calibri", 11))], [sg.ReadButton('Copy Original Tweet')], [sg.ReadButton('Copy Russian translation')], [sg.ReadButton('Copy English translation')], [ sg.Text('Geolocation', size=(15, 1), font=("Calibri", 11)), sg.InputCombo(['0', '1']) ], [ sg.Text('Relevance', size=(15, 1), font=("Calibri", 11)), sg.InputCombo(['0', '1']) ], [ sg.Text('Time', size=(15, 1), font=("Calibri", 11)), sg.InputCombo(['none', 'f', 'p'])
def main(): # define the form layout layout = [[ sg.Text('Animated Matplotlib', size=(40, 1), justification='center', font='Helvetica 20') ], [sg.Canvas(size=(640, 480), key='canvas')], [ sg.ReadButton('Exit', size=(10, 2), pad=((280, 0), 3), font='Helvetica 14') ]] # create the form and show it without the plot window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI' ).Layout(layout).Finalize() canvas_elem = window.FindElement('canvas') canvas = canvas_elem.TKCanvas while True: button, values = window.ReadNonBlocking() if button is 'Exit' or values is None: exit(69) def PyplotScatterWithLegend(): import matplotlib.pyplot as plt from numpy.random import rand fig, ax = plt.subplots() for color in ['red', 'green', 'blue']: n = 750 x, y = rand(2, n) scale = 200.0 * rand(n) ax.scatter(x, y, c=color, s=scale, label=color, alpha=0.3, edgecolors='none') ax.legend() ax.grid(True) return fig fig = PyplotScatterWithLegend() figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds figure_w, figure_h = int(figure_w), int(figure_h) photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h) canvas.create_image(640 / 2, 480 / 2, image=photo) figure_canvas_agg = FigureCanvasAgg(fig) figure_canvas_agg.draw() # Unfortunately, there's no accessor for the pointer to the native renderer tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
def MediaPlayerGUI(): background = '#F0F0F0' # Set the backgrounds the same as the background on the buttons sg.SetOptions(background_color=background, element_background_color=background) # Images are located in a subfolder in the Demo Media Player.py folder image_pause = './ButtonGraphics/Pause.png' image_restart = './ButtonGraphics/Restart.png' image_next = './ButtonGraphics/Next.png' image_exit = './ButtonGraphics/Exit.png' # A text element that will be changed to display messages in the GUI # define layout of the rows layout = [[ sg.Text('Media File Player', size=(17, 1), font=("Helvetica", 25)) ], [sg.Text('', size=(15, 2), font=("Helvetica", 14), key='output')], [ sg.ReadButton('Restart Song', button_color=(background, background), image_filename=image_restart, image_size=(50, 50), image_subsample=2, border_width=0), sg.Text(' ' * 2), sg.ReadButton('Pause', button_color=(background, background), image_filename=image_pause, image_size=(50, 50), image_subsample=2, border_width=0), sg.Text(' ' * 2), sg.ReadButton('Next', button_color=(background, background), image_filename=image_next, image_size=(50, 50), image_subsample=2, border_width=0), sg.Text(' ' * 2), sg.Text(' ' * 2), sg.Button('Exit', button_color=(background, background), image_filename=image_exit, image_size=(50, 50), image_subsample=2, border_width=0) ], [sg.Text('_' * 20)], [sg.Text(' ' * 30)], [ sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)), sg.Text(' ' * 2), sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)), sg.Text(' ' * 2), sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)) ], [ sg.Text(' Bass', font=("Helvetica", 15), size=(9, 1)), sg.Text('Treble', font=("Helvetica", 15), size=(7, 1)), sg.Text('Volume', font=("Helvetica", 15), size=(7, 1)) ]] # Open a form, note that context manager can't be used generally speaking for async forms window = sg.Window('Media File Player', auto_size_text=True, default_element_size=(20, 1), font=("Helvetica", 25), no_titlebar=True).Layout(layout) # Our event loop while (True): # Read the form (this call will not block) button, values = window.ReadNonBlocking() if button == 'Exit': break # If a button was pressed, display it on the GUI by updating the text element if button: window.FindElement('output').Update(button)
sg.T('', size=(44, 1), text_color='white', key='output') ], [ sg.CBox('Checkbox:', default=True, pad=((3, 0), 0), key='cbox'), sg.Listbox((1, 2, 3, 4), size=(8, 3), key='listbox'), sg.Radio('Radio 1', default=True, group_id='1', key='radio1'), sg.Radio('Radio 2', default=False, group_id='1', key='radio2') ], [ sg.Spin((1, 2, 3, 4), 1, key='spin'), sg.OptionMenu((1, 2, 3, 4), key='option'), sg.Combo(values=(1, 2, 3, 4), key='combo') ], [sg.Multiline('Multiline', size=(20, 3), key='multi')], [sg.Slider((1, 10), size=(20, 20), orientation='h', key='slider')], [ sg.ReadButton('Enable', button_color=('white', 'black')), sg.ReadButton('Disable', button_color=('white', 'black')), sg.ReadButton('Reset', button_color=('white', '#9B0023'), key='reset'), sg.ReadButton('Values', button_color=('white', 'springgreen4')), sg.Button('Exit', button_color=('white', '#00406B')) ]] window = sg.Window("Disable Elements Demo", default_element_size=(12, 1), text_justification='r', auto_size_text=False, auto_size_buttons=False, keep_on_top=True, grab_anywhere=False,
#!/usr/bin/env python import sys if sys.version_info[0] < 3: import PySimpleGUI27 as sg else: import PySimpleGUI as sg """ Demo of how to combine elements into your own custom element """ sg.SetOptions(element_padding=(0,0)) # sg.ChangeLookAndFeel('Dark') # --- Define our "Big-Button-Spinner" compound element. Has 2 buttons and an input field --- # NewSpinner = [sg.ReadButton('-', size=(2,1), font='Any 12'), sg.In('0', size=(2,1), font='Any 14', justification='r', key='spin'), sg.ReadButton('+', size=(2,1), font='Any 12')] # --- Define Window --- # layout = [ [sg.Text('Spinner simulation')], NewSpinner, [sg.T('')], [sg.Ok()] ] window = sg.Window('Spinner simulation').Layout(layout) # --- Event Loop --- # counter = 0 while True: button, value = window.Read()
if sys.version_info[0] < 3: import PySimpleGUI27 as sg else: import PySimpleGUI as sg ''' A chat window. Add call to your send-routine, print the response and you're done ''' sg.ChangeLookAndFeel('GreenTan') # give our window a spiffy set of colors layout = [[sg.Text('Your output will go here', size=(40, 1))], [sg.Output(size=(127, 30), font=('Helvetica 10'))], [ sg.Multiline(size=(85, 5), enter_submits=True, key='query'), sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0])) ]] window = sg.Window('Chat window', default_element_size=(30, 2), font=('Helvetica', ' 13'), default_button_element_size=(8, 2)).Layout(layout) # ---===--- Loop taking in user input and using it --- # while True: (button, value) = window.Read() if button is 'SEND': query = value['query'].rstrip() # EXECUTE YOUR COMMAND HERE
def Everything(): sg.ChangeLookAndFeel('TanBlue') column1 = [[ sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR, justification='center', size=(10, 1)) ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1', key='spin1') ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2', key='spin2') ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3', key='spin3') ]] layout = [ [ sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25)) ], [sg.Text('Here is some text.... and a place to enter text')], [sg.InputText('This is my text', key='in1', do_not_clear=True)], [ sg.Checkbox('Checkbox', key='cb1'), sg.Checkbox('My second checkbox!', key='cb2', default=True) ], [ sg.Radio('My first Radio! ', "RADIO1", key='rad1', default=True), sg.Radio('My second Radio!', "RADIO1", key='rad2') ], [ sg.Multiline( default_text= 'This is the default Text should you decide not to type anything', size=(35, 3), key='multi1', do_not_clear=True), sg.Multiline(default_text='A second multi-line', size=(35, 3), key='multi2', do_not_clear=True) ], [ sg.InputCombo(('Combobox 1', 'Combobox 2'), key='combo', size=(20, 1)), sg.Slider(range=(1, 100), orientation='h', size=(34, 20), key='slide1', default_value=85) ], [ sg.InputOptionMenu( ('Menu Option 1', 'Menu Option 2', 'Menu Option 3'), key='optionmenu') ], [ sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3), key='listbox'), sg.Slider( range=(1, 100), orientation='v', size=(5, 20), default_value=25, key='slide2', ), sg.Slider( range=(1, 100), orientation='v', size=(5, 20), default_value=75, key='slide3', ), sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10, key='slide4'), sg.Column(column1, background_color='gray34') ], [sg.Text('_' * 80)], [sg.Text('Choose A Folder', size=(35, 1))], [ sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Default Folder', key='folder', do_not_clear=True), sg.FolderBrowse() ], [ sg.ReadButton('Exit'), sg.Text(' ' * 40), sg.ReadButton('SaveSettings'), sg.ReadButton('LoadSettings') ] ] window = sg.Window('Form Fill Demonstration', default_element_size=(40, 1), grab_anywhere=False) # button, values = window.LayoutAndRead(layout, non_blocking=True) window.Layout(layout) while True: button, values = window.Read() if button is 'SaveSettings': filename = sg.PopupGetFile('Save Settings', save_as=True, no_window=True) window.SaveToDisk(filename) # save(values) elif button is 'LoadSettings': filename = sg.PopupGetFile('Load Settings', no_window=True) window.LoadFromDisk(filename) # load(form) elif button in ['Exit', None]: break
import PySimpleGUI27 as sg else: import PySimpleGUI as sg # Demonstrates a number of PySimpleGUI features including: # Default element size # auto_size_buttons # ReadButton # Dictionary return values # Update of elements in form (Text, Input) # do_not_clear of Input elements layout = [ [sg.Text('Enter Your Passcode')], [sg.Input(size=(10, 1), do_not_clear=True, key='input')], [sg.ReadButton('1'), sg.ReadButton('2'), sg.ReadButton('3')], [sg.ReadButton('4'), sg.ReadButton('5'), sg.ReadButton('6')], [sg.ReadButton('7'), sg.ReadButton('8'), sg.ReadButton('9')], [sg.ReadButton('Submit'), sg.ReadButton('0'), sg.ReadButton('Clear')], [ sg.Text('', size=(15, 1), font=('Helvetica', 18),
# redefine the chatbot text based progress bar with a graphical one chatterbot.utils.print_progress_bar = print_progress_bar chatbot = ChatBot('Ron Obvious', trainer='chatterbot.trainers.ChatterBotCorpusTrainer') # Train based on the english corpus chatbot.train("chatterbot.corpus.english") ################# GUI ################# layout = [[sg.Output(size=(80, 20))], [ sg.Multiline(size=(70, 5), enter_submits=True), sg.ReadButton('SEND', bind_return_key=True), sg.ReadButton('EXIT') ]] window = sg.Window('Chat Window', auto_size_text=True, default_element_size=(30, 2)).Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI web oracle --- # while True: button, (value, ) = window.Read() if button is not 'SEND': break string = value.rstrip() print(' ' + string) # send the user input to chatbot to get a response
def main(): fig = Figure() ax = fig.add_subplot(111) ax.set_xlabel("X axis") ax.set_ylabel("Y axis") ax.grid() # define the form layout layout = [[ sg.Text('Animated Matplotlib', size=(40, 1), justification='center', font='Helvetica 20') ], [sg.Canvas(size=(640, 480), key='canvas')], [ sg.Slider(range=(0, 10000), size=(60, 10), orientation='h', key='slider') ], [ sg.ReadButton('Exit', size=(10, 2), pad=((280, 0), 3), font='Helvetica 14') ]] # create the form and show it without the plot window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI' ).Layout(layout).Finalize() canvas_elem = window.FindElement('canvas') slider_elem = window.FindElement('slider') graph = FigureCanvasTkAgg(fig, master=canvas_elem.TKCanvas) canvas = canvas_elem.TKCanvas dpts = [randint(0, 10) for x in range(10000)] for i in range(len(dpts)): button, values = window.ReadNonBlocking() if button is 'Exit' or values is None: exit(69) slider_elem.Update(i) ax.cla() ax.grid() DATA_POINTS_PER_SCREEN = 40 ax.plot(range(DATA_POINTS_PER_SCREEN), dpts[i:i + DATA_POINTS_PER_SCREEN], color='purple') graph.draw() figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds figure_w, figure_h = int(figure_w), int(figure_h) photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h) canvas.create_image(640 / 2, 480 / 2, image=photo) figure_canvas_agg = FigureCanvasAgg(fig) figure_canvas_agg.draw() # Unfortunately, there's no accessor for the pointer to the native renderer tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)
# get list of PNG files in folder png_files = [folder + '\\' + f for f in os.listdir(folder) if '.png' in f] filenames_only = [f for f in os.listdir(folder) if '.png' in f] if len(png_files) == 0: sg.Popup('No PNG images in folder') exit(0) # define menu layout menu = [['File', ['Open Folder', 'Exit']], ['Help', ['About',]]] # define layout, show and read the window col = [[sg.Text(png_files[0], size=(80, 3), key='filename')], [sg.Image(filename=png_files[0], key='image')], [sg.ReadButton('Next', size=(8,2)), sg.ReadButton('Prev', size=(8,2)), sg.Text('File 1 of {}'.format(len(png_files)), size=(15,1), key='filenum')]] col_files = [[sg.Listbox(values=filenames_only, size=(60,30), key='listbox')], [sg.ReadButton('Read')]] layout = [[sg.Menu(menu)], [sg.Column(col_files), sg.Column(col)]] window = sg.Window('Image Browser', return_keyboard_events=True, location=(0,0), use_default_focus=False ).Layout(layout) # loop reading the user input and displaying image, filename i=0 while True: button, values = window.Read() # --------------------- Button & Keyboard --------------------- if button is None: break
filename = os.path.join(folder, fnames[0]) # name of first file in list image_elem = sg.Image(data=get_img_data(filename, first=True)) filename_display_elem = sg.Text(filename, size=(80, 3)) file_num_display_elem = sg.Text('File 1 of {}'.format(num_files), size=(15, 1)) # define layout, show and read the form col = [[filename_display_elem], [image_elem]] col_files = [[ sg.Listbox(values=fnames, change_submits=True, size=(60, 30), key='listbox') ], [ sg.ReadButton('Next', size=(8, 2)), sg.ReadButton('Prev', size=(8, 2)), file_num_display_elem ]] layout = [[sg.Column(col_files), sg.Column(col)]] window.Layout(layout) # Shows form on screen # loop reading the user input and displaying image, filename i = 0 while True: # read the form button, values = window.Read() # perform button and keyboard operations if button is None:
# ---------------- Create Form ---------------- sg.ChangeLookAndFeel('Black') sg.SetOptions(element_padding=(0, 0)) layout = [[sg.Text('')], [ sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text') ], [ sg.ReadButton('Pause', key='button', button_color=('white', '#001480')), 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) # ---------------- main loop ---------------- current_time = 0
import PySimpleGUI27 as sg else: import PySimpleGUI as sg """ Turn off padding in order to get a really tight looking layout. """ sg.ChangeLookAndFeel('Dark') sg.SetOptions(element_padding=(0, 0)) layout = [[sg.T('User:'******'User 1', 'User 2'), size=(20, 1)), sg.T('0', size=(8, 1))], [sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)), sg.T('1', size=(8, 1))], [sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black')], [sg.ReadButton('Start', button_color=('white', 'black')), sg.ReadButton('Stop', button_color=('gray50', 'black')), sg.ReadButton('Reset', button_color=('white', '#9B0023')), sg.ReadButton('Submit', button_color=('gray60', 'springgreen4')), sg.Button('Exit', button_color=('white', '#00406B'))]] window = sg.Window("Time Tracker", default_element_size=(12, 1), text_justification='r', auto_size_text=False, auto_size_buttons=False, no_titlebar=True, default_button_element_size=(12, 1)) window.Layout(layout) while True: button, values = window.Read() if button is None or button == 'Exit': break