def main(): global g_exit, g_response_time layout = [[sg.T('Enter width, height of graph')], [sg.In(size=(6, 1)), sg.In(size=(6, 1))], [sg.Ok(), sg.Cancel()]] window = sg.Window('Enter graph size').Layout(layout) b,v = window.Read() if b is None or b == 'Cancel': sys.exit(69) w, h = int(v[0]), int(v[1]) CANVAS_SIZE = (w,h) # start ping measurement thread sg.ChangeLookAndFeel('Black') sg.SetOptions(element_padding=(0,0)) layout = [ [sg.Quit( button_color=('white','black'))], [sg.Graph(CANVAS_SIZE, (0,0), (SAMPLES,SAMPLE_MAX),background_color='black', key='graph')],] window = sg.Window('Canvas test', grab_anywhere=True, background_color='black', no_titlebar=False, use_default_focus=False).Layout(layout).Finalize() graph = window.FindElement('graph') prev_response_time = None i=0 prev_x, prev_y = 0, 0 graph_value = 250 while True: # time.sleep(.2) button, values = window.ReadNonBlocking() if button == 'Quit' or values is None: break graph_offset = random.randint(-10, 10) graph_value = graph_value + graph_offset if graph_value > SAMPLE_MAX: graph_value = SAMPLE_MAX if graph_value < 0: graph_value = 0 new_x, new_y = i, graph_value prev_value = graph_value if i >= SAMPLES: graph.Move(-STEP_SIZE,0) prev_x = prev_x - STEP_SIZE graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white') # window.FindElement('graph').DrawPoint((new_x, new_y), color='red') prev_x, prev_y = new_x, new_y i += STEP_SIZE if i < SAMPLES else 0
""" 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 button == 'Ok' or button is None: # be nice to your user, always have an exit from your form break # --- do spinner stuff --- # counter += 1 if button =='+' else -1 if button == '-' else 0 window.FindElement('spin').Update(counter)
#!/usr/bin/env python import sys if sys.version_info[0] < 3: import PySimpleGUI27 as sg else: import PySimpleGUI as sg layout = [[sg.T('Calendar Test')], [sg.In('', size=(20, 1), key='input')], [sg.CalendarButton('Choose Date', target='input', key='date')], [sg.Ok(key=1)]] window = sg.Window('Calendar', grab_anywhere=False).Layout(layout) b, v = window.Read() sg.Popup(v['input'])