PyQt5 登录窗口
2019-08-25 python 1951
import sys from PyQt5.QtWidgets import QWidget,QApplication,QLineEdit,QLabel,QPushButton,QDesktopWidget from PyQt5.QtGui import QIcon,QPixmap from PyQt5.QtCore import Qt class Login(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 300, 160) self.setWindowIcon(QIcon("web.png")) self.setWindowFlags(Qt.FramelessWindowHint) #隐藏标题栏 self.setFixedSize(self.width(),self.height()) #禁止调整大小 #MainWindow.setWindowOpacity(0.85) # 设置窗口透明度 #MainWindow.setAttribute(QtCore.Qt.WA_TranslucentBackground) # 设置窗口背景透明 self.setAttribute(Qt.WA_TranslucentBackground) #窗体背景透明 #设置背景图片 pixmap = QPixmap("bg.png") lbl = QLabel(self) lbl.setPixmap(pixmap) lbl.setWindowOpacity(0.1) lbl_username = QLabel("用户名:",self) lbl_username.move(50,30) input_username = QLineEdit("",self) input_username.move(120, 30) lbl_passwd = QLabel("密码:",self) lbl_passwd.move(50, 60) input_passwd = QLineEdit("",self) input_passwd.move(120, 60) loginbtn = QPushButton("登录",self) loginbtn.move(70, 120) exitbtn = QPushButton("关闭", self) exitbtn.move(170, 120) exitbtn.clicked.connect(QApplication.instance().exit) self.center() self.setWindowTitle("用户登录") def center(self): qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) if __name__ =="__main__": app = QApplication(sys.argv) login = Login() login.show() sys.exit(app.exec_())
很赞哦! (0)