preface
Common GUI libraries
Introducing PySimpleGUI
PSG Document
Use of PSG library
#Standard import mode import PySimpleGUI as sg
#One time window event, values = sg.Window('Login Window', [[sg.T('Enter your Login ID'), sg.In(key='-ID-')], [sg.B('OK'), sg.B('Cancel') ]]).read(close=True) login_id = values['-ID-'] print(login_id)
#1. Import Library import PySimpleGUI as sg #2. Drawing layout layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(15,1), key='-OUTPUT-')], [sg.Input(key='-IN-')], [sg.Button('Show'), sg.Button('Exit')]] #3. Building windows window = sg.Window('Pattern 2B', layout) #4. Open cycle while True: event, values = window.read() #5. Write event if event in (sg.WIN_CLOSED, None, 'Exit'): break if event == 'Show': # Update the "output" text element to be the value of "input" element window['-OUTPUT-'].update(values['-IN-']) #6. Close the window window.close()
#! / usr/bin/python3 # -*- coding: utf-8 -* import myui,myevent def run_gui(): window = myui.make_main_window() #4. Open cycle while True: event, values = window.read() #5. Write event if event in (None, 'Exit'): break myevent.apply_event(window,event,values) #6. Close the window window.close() if __name__ == '__main__': run_gui()
#! / usr/bin/python3 # -*- coding: utf-8 -* #1. Import Library import PySimpleGUI as sg def make_main_window(): #2. Drawing layout app_label = [sg.Text('Your typed chars appear here:'), sg.Text(size=(15,1), key='-OUTPUT-')] app_input = [sg.Input(key='-IN-')] app_btn = [sg.Button('Show'), sg.Button('Exit')] layout = [ [app_label], [app_input], [app_btn] ] #3. Building windows return sg.Window('Pattern 2B', layout)
#! / usr/bin/python3 # -*- coding: utf-8 -* def show_event(window, values): #Show event code window['-OUTPUT-'].update(values['-IN-']) def apply_event(window,event,values): #All interface events if event == 'Show': show_event(window, values)
def make_win1(): col1 = sg.Column([ # Categories sg.Frame [sg. Frame ('file name: ', [sg. Listbox ([], key=' - dirlist - ', size=(250, 120), enable_events=True)]], size=(250, 120))], # Information sg.Frame [sg. Frame ('data file: ', [sg. Listbox ([], key=' - filelist - ', size=(250, 180), enable_events=True)]], size=(250, 180))], [sg. Frame ('measurement information: '[ [sg. T ('process: '), sg. T ('111', k='- spec -')], [sg. T ('part No.: '), sg. T ('222', k='- pn -')], [sg. T ('Batch No.: '), sg. T ('333', k='- lot -')], [sg. T ('Remark: '), sg. T ('444', k='- note -')], [sg. T ('Time: '), sg. T ('555', k='- datetime -')], [sg. T ('Other: '), sg. T ('666', k='- other -')], ], size=(250, 150))], [sg. Frame ('Throw up status: '[ [sg. T ('status: '), sg. T ('111', k='- status -')], ], size=(250, 50))], ]) col2 = sg.Column([ [sg.Frame ('Original data: ', [sg.Table ([' '* 7,' '* 7,' '* 7,' '* 7,' '* 7,' '* 7,' '* 7,' '* 7,' '* 7]], Headings=['dimension number ',' standard value ',' upper tolerance ',' lower tolerance ',' data one ',' data two '], auto_size_columns=True, max_col_width=500, size=(400, 500))]], size=(400, 500))], ]) Top_btn=[sg. Button ('open '), sg. Button ('save'), sg. Button( 'Popup'), sg. Button ('information '), sg. Button ('set'), sg. Button ('exit '),] menu_def = [['&File', ['&Open', '&Save Ctrl-S', '&Properties', 'E&xit']], ['&Edit', ['&Paste', ['Special', 'Normal', ], 'Undo'], ], ['&Toolbar', ['---', 'Command &1', 'Command &2', '---', 'Command &3', 'Command &4']], ['&Help', '&About...'], ] TopMenu = [sg.Menu(menu_def)] Output=[sg. Frame ('real time output: ', [sg. Output (size=(92, 10))]]] statusbar = [sg.StatusBar(time.strftime('%Y/%m/%d %H:%M:%S'))] # The final layout is a simple one layout = [ [TopMenu], [top_btn], [col1, col2], [Output], [statusbar] ] Return sg. Window ('SPC uploading program for forming size ', layout, finalize=True, disable_close=True)
Introduction to psgdemos
#Installation pip install psgdemos
Video Tutorials
summary