Python-PySimpleGUI
2022/1/24 1:04:24
本文主要是介绍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-PySimpleGUI的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python