def main(): dictionary_of_figures = { 'Axis Grid': create_axis_grid, 'Subplot 3D': create_subplot_3d, 'Scales': create_pyplot_scales, 'Basic Figure': create_figure } layout = [ [sg.T('Matplotlib Example', font='Any 20')], [ sg.Listbox(dictionary_of_figures.keys(), size=(15, 5), key='-LB-'), sg.Image(key='-IMAGE-') ], [sg.B('Draw'), sg.B('Exit')], ] window = sg.Window('Title', layout, finalize=True) image_element = window['-IMAGE-'] # type: sg.Image while True: event, values = window.read() if event == 'Exit' or event == sg.WIN_CLOSED: break if event == 'Draw': func = dictionary_of_figures[values['-LB-'][0]] draw_figure(func(), image_element) window.close()
def main(): layout = [ [sg.T('Matplotlib Example', font='Any 20')], [sg.Image(key='-IMAGE-')], [sg.B('Draw'), sg.B('Exit')], ] window = sg.Window('Title', layout) while True: event, values = window.read() if event == 'Exit' or event == sg.WIN_CLOSED: break if event == 'Draw': draw_figure(create_figure(), window['-IMAGE-']) window.close()
python3 apiDiff01.py --web result? No problem 2) Run using the Tk platform: python3 apiDiff01.py result? File "apiDiff01.py", line 33, in <module> window = sg.Window('CatalogQuerySG.py', web_start_browser=False, web_port=8080).Layout(layout) TypeError: __init__() got an unexpected keyword argument 'web_port' ''' import sys if '--web' in sys.argv: import PySimpleGUIWeb as sg else: import PySimpleGUI as sg layout = [[sg.T('foo')]] window = sg.Window('CatalogQuerySG.py', web_start_browser=False, web_port=8080).Layout(layout) window.Read(timeout=0) window.Close()
ball.gui_circle_figure = graph_elem.DrawCircle((x, y), r, fill_color='black', line_color='red') # ------------------- Build and show the GUI Window ------------------- graph_elem = sg.Graph((600, 400), (0, 400), (600, 0), enable_events=True, key='_GRAPH_', background_color='lightblue') layout = [ [ sg.Text('Ball Test'), sg.T('My IP {}'.format(socket.gethostbyname(socket.gethostname()))) ], [graph_elem], # [sg.Up(), sg.Down()], [sg.B('Kick'), sg.Button('Exit')] ] window = sg.Window( 'Window Title', layout, ).Finalize() area = Playfield() area.add_balls() # ------------------- GUI Event Loop -------------------
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.MultilineOutput(size_px=(980, 400), key='_OUTPUT_')], # [ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='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, 1), icon=DEFAULT_ICON, font=('Helvetica', ' 17'), default_button_element_size=(8, 2), return_keyboard_events=False, ) window.Layout(layout) # ---===--- Loop taking in user input and using it to query HowDoI --- # command_history = [] history_offset = 0 while True: event, values = window.Read() # print(event, values) if type(event) is int: event = str(event) if event == 'SEND': query = values['query'].rstrip() window.Element('_OUTPUT_').Update(query, append=True) print(query) QueryHowDoI(query, 1, values['full text'], window) # 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 event == None or event == 'EXIT': # if exit button or closed using X break elif 'Up' in event 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 event 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 event: # clear currently line window.FindElement('query').Update('') window.Close()
table_data = make_table(num_rows=15, num_cols=6) # ------------------ Create a window layout ------------------ layout = [[ sg.Table(values=table_data, enable_events=True, display_row_numbers=True, font='Courier 14', row_header_text='Row #', key='_table_', text_color='red') ], [sg.Button('Exit')], [ sg.T('Selected rows = '), sg.T('', size=(30, 1), key='_selected_rows_') ], [ sg.T('Selected value = '), sg.T('', size=(30, 1), key='_selected_value_') ]] # ------------------ Create the window ------------------ window = sg.Window('Table Element Example').Layout(layout) # ------------------ The Event Loop ------------------ while True: event, values = window.Read() print(event, values) if event in (None, 'Exit'):
# msg = "Welcome to Xpnsit, the best way to manage your expenses! To begin, login or signup below" # title = 'Xpnsit v0.1' # login_fields = ['Username','Password'] # gui.Popup(msg,title = title) login_window = sg.Window('Xpnsit v0.1') space1 = ' ' ## Tabs so that I could justify the fields and buttons space2 = ' ' layout = [ [sg.Text('Welcome to Xpnsit, the best way to manage your expenses! To begin, login or signup below.',font = ('Helvetica',15),justification='center')], [sg.T(space1),sg.Text('Username', size=(15, 1)), sg.InputText(key='_name_')], [sg.T(space1),sg.Text('Password', size=(15, 1)), sg.InputText(key='_password_',password_char = '*')], [sg.T('')], [sg.T(space2),sg.Button('Login', tooltip='Login',bind_return_key=True), sg.Button('Signup',tooltip='Signup (if you haven\'t already)')] ] login_window.Layout(layout) # dashboard.Layout(dashboard_layout) # global login_window,dashboard dash_active = False while True: event, values = login_window.Read() if event is None or event == 'Exit':
def mainloop(file, database, savedump, records, orderby, guimode): """Get user Janpanse input then parse it and record new words into database.""" jmd = Jamdict() knp = KNP() jumandict = sqlite3.connect(database) dictcursor = jumandict.cursor() dictcursor.execute( "CREATE TABLE IF NOT EXISTS words (id INTEGER PRIMARY KEY, name TEXT UNIQUE, desc TEXT, count INTEGER)" ) dumper = open(savedump, 'w') # Pass any command line argument for Web use if guimode == "web": # if there is use the Web Interface import PySimpleGUIWeb as sg import socket elif guimode == "tk": # default uses the tkinter GUI import PySimpleGUI as sg elif guimode == "qt": import PySimpleGUIQt as sg else: import PySimpleGUIWx as sg # All the stuff inside your window. header_list = [ "ID", "词汇", "读法", "原形", "词性", "词性细分", "活用型", "活用形", "语义信息", "代表符号" ] uifont = "Ariel 32" left_column_layout = [ [ sg.T("输入日语"), sg.FolderBrowse(), ], [ sg.Multiline("", size=(75, 10), key="nihongo"), ], [ sg.Button("分析", size=(30, 3), font=uifont, button_color=('white', 'green'), key="submit"), sg.Button("退出", size=(30, 3), font=uifont, button_color=('white', 'red'), key="exit") ], [ sg.Listbox(values=[], enable_events=True, size=(75, 20), key="parsedwords") ], ] right_column_layout = [ [sg.T("词汇意义")], [ sg.Listbox(values=[], enable_events=True, size=(75, 33), key="foundentries") ], ] layout = [[ sg.VSeperator(), sg.Column(left_column_layout), sg.VSeperator(), sg.Column(right_column_layout), ]] # Create the Window if guimode == "web": hostname = socket.gethostname() local_ip = socket.gethostbyname(hostname) print("local_ip is " + local_ip) window = sg.Window('日语学习', layout, web_ip=local_ip, web_port=8888, web_start_browser=False) else: window = sg.Window('日语学习', layout) resultlist = [] # Run the Event Loop while True: event, values = window.read() if event == "exit" or event == sg.WIN_CLOSED: break # Folder name was filled in, make a list of files in the folder if event == "submit": userinput = values["nihongo"] print("=================================") print(userinput) userinput = userinput.strip() userinput = userinput.encode('utf-8', 'surrogatepass').decode('utf-8') dumper.write(userinput + "\n\n") result = knp.parse(userinput.replace("\n", "")) print("=================================") print("词素") resultlist = result.mrph_list() parsedwords = [] for mrph in resultlist: # 访问每个词素 if mrph.midasi in {"、", "。", "「", "」", "\␣"}: continue message = "\tID:{}, 词汇:{}, 读法:{}, 原形:{}, 词性:{}, 词性细分:{}, 活用型:{}, 活用形:{}, 语义信息:{}, 代表符号:{}".format( mrph.mrph_id, mrph.midasi, mrph.yomi, mrph.genkei, mrph.hinsi, mrph.bunrui, mrph.katuyou1, mrph.katuyou2, mrph.imis, mrph.repname) print(message) dumper.write(message + "\n") parsedwords += [message] # use exact matching to find exact meaning dictcheck = jmd.lookup(mrph.genkei) if len(dictcheck.entries) == 0: dictcheck = jmd.lookup(mrph.midasi) if len(dictcheck.entries) == 0: dictcheck = jmd.lookup(mrph.yomi) if len(dictcheck.entries) > 0: desc = "" for entry in dictcheck.entries: desc = desc + entry.text(compact=False, no_id=True) + "\n" print("\n" + desc) dumper.write("\n" + desc + "\n") dictcursor.execute( 'INSERT INTO words (name, desc, count) VALUES ("{}", "{}", "{}") ON CONFLICT (name) DO UPDATE SET count = count + 1' .format(mrph.genkei.replace('"', '""'), desc.replace('"', '""'), 1)) jumandict.commit() window["parsedwords"].update(parsedwords) elif event == "parsedwords": # A file was chosen from the listbox selectedword = values["parsedwords"][0] print(selectedword) selectedid = int(selectedword.split(',')[0].split(':')[1].strip()) print("selectedid=" + str(selectedid) + " among " + str(len(resultlist)) + " entries") foundentries = [] for mrph in resultlist: # 访问每个词素 if selectedid != mrph.mrph_id: continue message = "\tID:{}, 词汇:{}, 读法:{}, 原形:{}, 词性:{}, 词性细分:{}, 活用型:{}, 活用形:{}, 语义信息:{}, 代表符号:{}".format( mrph.mrph_id, mrph.midasi, mrph.yomi, mrph.genkei, mrph.hinsi, mrph.bunrui, mrph.katuyou1, mrph.katuyou2, mrph.imis, mrph.repname) print(message) # use exact matching to find exact meaning dictcheck = jmd.lookup(mrph.genkei) if len(dictcheck.entries) == 0: dictcheck = jmd.lookup(mrph.midasi) if len(dictcheck.entries) == 0: dictcheck = jmd.lookup(mrph.yomi) foundentries += [message] foundentries += ["==================================="] if len(dictcheck.entries) > 0: for entry in dictcheck.entries: desc = entry.text(compact=False, no_id=True) print("\n" + desc) foundentries += [desc] window["foundentries"].update(foundentries) window.close() jumandict.close() dumper.close()
], [ sg.Button('RelayJ3 ON', size=(15, 3)), sg.Button('RelayJ3 OFF', size=(15, 3)) ], [ sg.Button('RelayJ4 ON', size=(15, 3)), sg.Button('RelayJ4 OFF', size=(15, 3)) ], [ sg.Button('RelayJ5 ON', size=(15, 3)), sg.Button('RelayJ5 OFF', size=(15, 3)) ], [sg.Text("_" * 100)], [sg.Button('Quit program', size=(15, 3))], [sg.T()], ] #Creo la finestra di configurazione e comando #window = sg.Window('HQSOL Srl - program by RSA lab', default_element_size=(40, 1)).Layout(layout) window = sg.Window('HQSOL Srl - program by RSA lab', layout, web_ip='localhost', web_port=8888, web_start_browser=True) #Loop che processa i comandi while True: event, values = window.Read() if event == "Set Connection": break if event is None or event == 'Quit program': raise SystemExit("Program terminated")