Code
import PySimpleGUI as sg
import sys
layout_pwd = [
[sg.Text('请输入密码!')],
[sg.Input(password_char='*')],
[sg.Button(' 确定 '), sg.Button(' 关闭 ')]
]
w = sg.Window('请输入密码', layout=layout_pwd)
while True:
event, values = w.read()
print(event)
print(values)
if event in (None, ' 关闭 '):
sys.exit()
elif values[0] == '123':
print(values[0])
break
w.close()
layout = [[sg.Text('选择xml文件夹')], [sg.Input(), sg.FolderBrowse('浏览')],
[sg.Text('选择"计算机应用基础"excel文件')], [sg.Input(), sg.FileBrowse('浏览')],
[sg.Text('选择"考试通知单"excel文件')], [sg.Input(), sg.FileBrowse('浏览')],
[sg.Text('处理进度')], [sg.ProgressBar(1000, orientation='h', size=(40, 20), key='progressbar')],
[sg.Button(' 开始处理 '), sg.Button(' 关闭 ')]]
window = sg.Window('合并考试通知单(xlrd and xlutils 版)', layout, icon='icon/puple128.ico')
while True:
event, values = window.read()
if event in (None, ' 关闭 '):
break
window.close()
效果:
image.png密码正确后,窗口自动跳转到下一窗口;
增加过期时间和密码错误判断
# 设置软件过期时间
data = '2020-8-21 13:50:00'
data_array = time.strptime(data, "%Y-%m-%d %H:%M:%S")
timeStamp = int(time.mktime(data_array))
layout_pwd = [
[sg.Text('请输入密码!')],
[sg.Input(password_char='*')],
[sg.Button('确定', size=(10, 1)), sg.Button('关闭', size=(10, 1))]
]
w = sg.Window('请输入密码', layout=layout_pwd)
while True:
event, values = w.read()
print(event)
print(values)
if event in (None, '关闭'):
sys.exit()
elif time.time() > timeStamp:
sg.Popup('软件已过期!请联系作者')
elif values[0] == '123':
print(values[0])
break
else:
sg.Popup('密码不正确!')
w.close()
网友评论