Python-PySimpleGUI
作者:互联网
#***************************************************************模板****************************************************** '''import PySimpleGUI as sg # Part 1 - 导入库 # 定义窗口的内容 layout = [ [sg.Text("请输入基本信息")], # Part 2 - 排版 [sg.Text("姓名"),sg.Input("张明明")], [sg.Text("性别"),sg.Input("男")], [sg.Text("国籍"),sg.Input("中国")], [sg.Button('确认'),sg.Button('取消')] ] # 创建窗口 window = sg.Window('Window Title', layout) # Part 3 - 窗口定义 # Display and interact with the Window while True: event, values = window.read() # Part 4 - 开启主循环 window.read() if event==None: break if event =="确认": # Do something with the information gathered sg.Popup('Hello', values[0], "! Thanks for trying PySimpleGUI") if event =="取消": # Do something with the information gathered sg.Popup('Hello', values[0], "! Thanks for trying PySimpleGUI") # Finish up by removing from the screen window.close() # Part 5 - 关闭窗口 ''' #**********************文本******************************************* ''' import PySimpleGUI as sg # Part 1 - 导入库 #text = 优美胜于丑陋(Python 以编写优美的代码为目标) #明了胜于晦涩(优美的代码应当是明了的,命名规范,风格相似) #简洁胜于复杂(优美的代码应当是简洁的,不要有复杂的内部实现) #复杂胜于凌乱(如果复杂不可避免,那代码间也不能有难懂的关系,要保持接口简洁) #扁平胜于嵌套(优美的代码应当是扁平的,不能有太多的嵌套) #间隔胜于紧凑(优美的代码有适当的间隔,不要奢望一行代码解决问题) #可读性很重要(优美的代码是可读的) #即便假借特例的实用性之名,也不可违背这些规则(这些规则至高无上) # # 定义窗口的内容 layout = [[sg.T(text, key='-TEXT-', size=(50,20), font=('黑体',20), auto_size_text=True, enable_events=False, relief='solid', border_width=5, text_color='red', background_color='white', justification='r', pad=None, right_click_menu=['1',['1',['1-1','1-2'],'2','3']], )], [sg.Button('确认'),sg.Button('取消')] ] # 创建窗口 window = sg.Window('Window Title', layout) # Part 3 - 窗口定义 # Display and interact with the Window while True: event, values = window.read() # Part 4 - 开启主循环 window.read() print(event) if event==None: break if event=='确认': break # Finish up by removing from the screen window.close() # Part 5 - 关闭窗口 ''' ############################################文本输入框############################# '''import PySimpleGUI as sg # Part 1 - 导入库 # 定义窗口的内容 layout = [ [sg.Text("请输入基本信息")], # Part 2 - 排版 [sg.Text("姓名",key='-NAME-'),sg.Input("张明明")], [sg.Text("性别"),sg.Input("男")], [sg.Text("国籍"),sg.Input("中国")], [sg.Button('更改姓名的颜色'),sg.Button('取消')] ] # 创建窗口 window = sg.Window('Window Title', layout) # Part 3 - 窗口定义 # Display and interact with the Window while True: event, values = window.read() # Part 4 - 开启主循环 window.read() if event==None: break if event =="更改姓名的颜色": # Do something with the information gathered window['-NAME-'].update( value='Name', background_color='grey', text_color='red', visible='' ) if event =="取消": # Do something with the information gathered sg.Popup('Hello', values[0], "! Thanks for trying PySimpleGUI") # Finish up by removing from the screen window.close() # Part 5 - 关闭窗口''' ##############################################文本3########################################## import PySimpleGUI as sg # Part 1 - 导入库 # 定义窗口的内容 layout = [ [sg.Button('中文'),sg.Button('English')] , [sg.Text("请输入基本信息",key='-TEXT3-')], [sg.Text("姓名",key='-TEXT4-'),sg.Input("张明明")], [sg.Text("性别",key='-TEXT5-'),sg.Input("男")], [sg.Text("国籍",key='-TEXT6-'),sg.Input("中国")], [sg.Button('确认',key='-TEXT7-'), sg.Button('取消',key='-TEXT8-')], ] # 创建窗口 window = sg.Window('Window Title', layout) # Part 3 - 窗口定义 # Display and interact with the Window while True: event, values = window.read() # Part 4 - 开启主循环 window.read() print(event) if event==None: break if event =='English': window['-TEXT3-'].update(value='Pls input your name') window['-TEXT4-'].update(value='Name') window['-TEXT5-'].update(value='Sex') window['-TEXT6-'].update(value='Nation') window['-TEXT7-'].update('Confirm') window['-TEXT8-'].update('Cancle') if event =='中文': window['-TEXT3-'].update(value='请输入个人信息') window['-TEXT4-'].update(value='姓名') window['-TEXT5-'].update(value='性别') window['-TEXT6-'].update(value='国籍') window['-TEXT7-'].update('确认') window['-TEXT8-'].update('取消') # Finish up by removing from the screen window.close() # Part 5 - 关闭窗口
标签:Python,Text,update,PySimpleGUI,window,Part,sg,event 来源: https://www.cnblogs.com/hiroren/p/15837977.html