今天为大家介绍一个利用开发登录界面模板,基于pyqt5库,pyqt5这也一个pythongui界面开发的库,非常强
本例,展示了通过登录界面打开主界面的实现方式。
在开始实现登录界面前,先给大家普及一下pyqt5的安装以及使用
1. pyqt5简单使用
安装
1
2
|
pip install pyqt5
pip3. 5 install pyqt5 - tools
|
界面化操作
1.在win+r中输入designer并敲回车,即可启动designer。一般选择“main window”点击“create”即可创建。
若在win+r中输入designer并敲回车后无反应,可以直接搜designer.exe直接启动
2.创建后,可以方便快捷的用qt designer画出对应框体,如通过combo box添加下拉选择的控件;通过push button添加按钮;通过list widget添加列表框;通过table widget添加数据表格框,table中设置列数(右键-edit items-colums),调整框体位置和文字大小,背景颜色以及windowtitle来优化界面显示,使用快捷键ctrl+r预览当前编写的gui显示如下:
3.点击保存,生成*.ui的文件,本例中为test.ui,保存在d:\py\deploy文件夹下
2.开始实现登录界面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
import sys
from pyqt5.qtwidgets import *
from pyqt5.qtcore import *
from pyqt5.qtgui import *
#创建主窗口
class mainwindow(qmainwindow):
def __init__( self , * args, * * kwargs):
super ().__init__( * args, * * kwargs)
self .setwindowtitle( '主界面' )
self .showmaximized()
#对话框
class logindialog(qdialog):
def __init__( self , * args, * * kwargs):
super ().__init__( * args, * * kwargs)
self .setwindowtitle( '登录界面' )
self .resize( 200 , 200 )
self .setfixedsize( self .width(), self .height())
self .setwindowflags(qt.windowclosebuttonhint)
###### 设置界面控件
self .frame = qframe( self )
self .verticallayout = qvboxlayout( self .frame)
self .lineedit_account = qlineedit()
self .lineedit_account.setplaceholdertext( "请输入账号" )
self .verticallayout.addwidget( self .lineedit_account)
self .lineedit_password = qlineedit()
self .lineedit_password.setplaceholdertext( "请输入密码" )
self .verticallayout.addwidget( self .lineedit_password)
self .pushbutton_enter = qpushbutton()
self .pushbutton_enter.settext( "确定" )
self .verticallayout.addwidget( self .pushbutton_enter)
self .pushbutton_quit = qpushbutton()
self .pushbutton_quit.settext( "取消" )
self .verticallayout.addwidget( self .pushbutton_quit)
###### 绑定按钮事件
self .pushbutton_enter.clicked.connect( self .on_pushbutton_enter_clicked)
self .pushbutton_quit.clicked.connect(qcoreapplication.instance().quit)
def on_pushbutton_enter_clicked( self ):
# 账号判断
if self .lineedit_account.text() = = "":
return
# 密码判断
if self .lineedit_password.text() = = "":
return
# 通过验证,关闭对话框并返回1
self .accept()
#程序入门
if __name__ = = "__main__" :
app = qapplication(sys.argv)
dialog = logindialog()
if dialog.exec_() = = qdialog.accepted:
the_window = mainwindow()
the_window.show()
sys.exit(app.exec_())
|
到此这篇关于python通过pyqt5实现登录界面的示例代码的文章就介绍到这了,更多相关pyqt5 登录界面内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://juejin.cn/post/7000326245061754911