import PySimpleGUI as sg

sg.theme('BrightColors') # 设置主题
layout = [ # 定义布局,确定行数
[sg.Text('姓名'), sg.InputText('名字')],
[sg.Radio('Radio1', 'Radio', key='-Radio1-')], #key是唯一标识此元素
[sg.Checkbox('Checkbox1', key='-Checkbox1-')],
[sg.InputText('InputText', size=(10, 10), change_submits=False, key='-InputText-')], #change_submits对此元素的更改将立即报告为事件
[sg.Input('Input', size=(5, 5))],
[sg.InputCombo(['InputCombo1', 'InputCombo2', 'InputCombo3'])],
[sg.CalendarButton('CalendarButton', close_when_date_chosen=True, enable_events=True, key='-CalendarButton-')],
# 日历选择器
[sg.Listbox(['A-1', 'A-2', 'A-3', 'A-4', 'A-5', ])],
[sg.Slider((1, 100), default_value=1, enable_events=False, orientation='h')], # 滑动杆 orientation 横竖
[sg.Combo(['3', '5', '7'], '3', key='-Combo1-', background_color='white', size=(15, 1), enable_events=True)],
[sg.Image(key="-IMAGE-", size=(100, 100), filename='my34601.png')], # 只能png或者gif图片
[sg.Button('确认'), sg.Button('提交', key='-submit-')]
]
window = sg.Window('提交信息', layout) # 创建窗口
while True: # 事件循环
event, values = window.read() # 读取窗口,返回事件和值
print(event, values)
if event is None: # 窗口关闭,程序中止运行
break
if event == '-CalendarButton-':
print(event)
if event == '-submit-':
if len(values['-InputText-']) > 5:
sg.Popup('InputText输入内容不能超过5个字符')
print(values['-InputText-'])
print(type(values['-InputText-']))



window.close() # 窗口关闭
###############################针对图片######################
# from PIL import Image,ImageTk
# import PySimpleGUI as sg
# from PIL import Image,ImageTk
#
# image = Image.open('my34601.png')
# image.show()

#################框架#####################
import PySimpleGUI as sg

sg.theme('BrightColors') # 设置主题
layout = [ # 定义布局,确定行数
[sg.Text('请输入基本信息')],
[sg.Text('姓名'), sg.InputText('名字')],
[sg.Text('性别'), sg.InputText('男')]
]
window = sg.Window('提交信息', layout) # 创建窗口
while True: # 事件循环
event, values = window.read() # 读取窗口,返回事件和值
print(event, values)
if event is None: # 窗口关闭,程序中止运行
break
else:
sg.Popup('WYF')

window.close() # 窗口关闭

###########中英切换主要是updata#############

import PySimpleGUI as sg

sg.theme('BrightColors') # 设置主题
layout = [ # 定义布局,确定行数
[sg.Button('中文'), sg.Button('English')],
[sg.Text('请输入基本信息', size=(40, 1), key='-enter-')],
[sg.Text('', key='-name-'), sg.InputText('')],
[sg.Text('性别', key='-sex-'), sg.InputText('')],
[sg.Text('国籍', key='-nationality-'), sg.InputText('')],
[sg.Button('确认', key='-CONF-'), sg.Button('提交', key='-submit-')]
]
window = sg.Window('提交信息', layout) # 创建窗口
while True: # 事件循环
event, values = window.read() # 读取窗口,返回事件和值
# print(event, values)
if event is None: # 窗口关闭,程序中止运行
break
if event == 'English':
window['-enter-'].update(value='Please input message', visible=True)
window['-name-'].update(value='Name', visible=True)
window['-sex-'].update(value='Sex', visible=True)
window['-nationality-'].update(value='Nationality', visible=True)
window['-CONF-'].update('Confirm', visible=True)
window['-submit-'].update('Submit', visible=True)
if event == '中文':
window['-enter-'].update(value='请输入信息', visible=True)
window['-name-'].update(value='姓名', visible=True)
window['-sex-'].update(value='性别', visible=True)
window['-nationality-'].update(value='国籍', visible=True)
window['-CONF-'].update('确认', visible=True)
window['-submit-'].update('提交', visible=True)

window.close() # 窗口关闭