pyqt5登录页面跳转
时间: 2024-01-02 22:19:37 浏览: 80
可以通过以下步骤实现pyqt5登录页面跳转:
1. 创建两个窗口,一个是登录窗口,一个是主窗口。
2. 在登录窗口中添加用户名和密码输入框以及登录按钮。
3. 在登录按钮的clicked信号中,检查用户名和密码是否正确,如果正确则隐藏登录窗口并显示主窗口。
4. 在主窗口中添加返回登录按钮,点击该按钮时隐藏主窗口并显示登录窗口。
下面是一个简单的示例代码:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('登录')
self.resize(300, 200)
self.username_label = QLabel('用户名:', self)
self.username_label.move(50, 50)
self.username_edit = QLineEdit(self)
self.username_edit.move(110, 50)
self.password_label = QLabel('密码:', self)
self.password_label.move(50, 100)
self.password_edit = QLineEdit(self)
self.password_edit.setEchoMode(QLineEdit.Password)
self.password_edit.move(110, 100)
self.login_button = QPushButton('登录', self)
self.login_button.move(110, 150)
self.login_button.clicked.connect(self.login)
def login(self):
username = self.username_edit.text()
password = self.password_edit.text()
if username == 'admin' and password == '123456':
self.hide()
main_window.show()
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('主界面')
self.resize(300, 200)
self.return_button = QPushButton('返回登录', self)
self.return_button.move(110, 100)
self.return_button.clicked.connect(self.return_login)
def return_login(self):
self.hide()
login_window.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
login_window = LoginWindow()
main_window = MainWindow()
login_window.show()
sys.exit(app.exec_())
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)