pysimplegui登录.py、注册.py与主界面.py的跳转
时间: 2023-05-19 22:02:57 浏览: 163
可以使用 PySimpleGUI 的 Window.hide() 和 Window.un_hide() 方法来实现登录.py、注册.py与主界面.py的跳转。具体实现可以参考以下代码:
在登录.py中:
```
import PySimpleGUI as sg
layout = [[sg.Text('用户名:'), sg.Input(key='username')],
[sg.Text('密码:'), sg.Input(key='password', password_char='*')],
[sg.Button('登录'), sg.Button('注册')]]
window = sg.Window('登录', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == '登录':
# 验证用户名和密码是否正确
if values['username'] == 'admin' and values['password'] == '123456':
# 隐藏当前窗口
window.hide()
# 打开主界面.py
exec(open('主界面.py').read())
# 显示当前窗口
window.un_hide()
else:
sg.popup('用户名或密码错误!')
elif event == '注册':
# 隐藏当前窗口
window.hide()
# 打开注册.py
exec(open('注册.py').read())
# 显示当前窗口
window.un_hide()
window.close()
```
在注册.py中:
```
import PySimpleGUI as sg
layout = [[sg.Text('用户名:'), sg.Input(key='username')],
[sg.Text('密码:'), sg.Input(key='password', password_char='*')],
[sg.Button('注册'), sg.Button('返回登录')]]
window = sg.Window('注册', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == '注册':
# 注册用户
sg.popup('注册成功!')
elif event == '返回登录':
# 隐藏当前窗口
window.hide()
# 打开登录.py
exec(open('登录.py').read())
# 显示当前窗口
window.un_hide()
window.close()
```
在主界面.py中:
```
import PySimpleGUI as sg
layout = [[sg.Text('欢迎使用主界面!')],
[sg.Button('退出')]]
window = sg.Window('主界面', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == '退出':
break
window.close()
```
相关推荐









