PyQt5 Tim界面 开源

昨天看到州先生发布的Tim界面的PyQt栗子我来跟个风~
效果:


tim.gif

我这个没他做的细,主要是最近要中考了.大概基本的样式和效果都呈现于此。下面是全部代码.

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Tim.ui'
#
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QGraphicsDropShadowEffect
from PyQt5.QtGui import QTextCursor
import sys, time, threading, os, psutil, subprocess, shutil, winreg, requests
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QMessageBox
#全局变量
QQ = 1
class Tim(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.init_ui()
    def init_ui(self): #BreathUI控件生成代码
        self.setObjectName("Form")
        self.resize(768, 581)
        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框
        self.setAttribute(Qt.WA_TranslucentBackground)  # 设置窗口背景透明
        self.label = QtWidgets.QLabel(self)
        self.label.setGeometry(QtCore.QRect(0, 0, 761, 581))
        self.label.setText("")
        self.label.setPixmap(QtGui.QPixmap("Tim\Background.png"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self)
        self.label_2.setGeometry(QtCore.QRect(49, 49, 351, 483))
        self.label_2.setText("")
        self.label_2.setPixmap(QtGui.QPixmap(r"Tim\bk.png"))
        self.label_2.setScaledContents(True)
        self.label_2.setObjectName("label_2")
        self.label_4 = QtWidgets.QLabel(self)
        self.label_4.setGeometry(QtCore.QRect(490, 240, 54, 12))
        self.label_4.setStyleSheet("font-family:微软雅黑;\n"
"color:#1191FF;")
        self.label_4.setObjectName("label_4")
        self.label_6 = QtWidgets.QLabel(self)
        self.label_6.setGeometry(QtCore.QRect(610, 240, 54, 12))
        self.label_6.setStyleSheet("font-family:微软雅黑;\n"
"color:#A6A6A6;")
        self.label_6.setObjectName("label_6")
        self.lineEdit = QtWidgets.QLineEdit(self)
        self.lineEdit.setGeometry(QtCore.QRect(460, 290, 231, 20))
        self.lineEdit.setStyleSheet("font-family:微软雅黑;\n"
"background:transparent;\n"
"border:-1px;")
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(self)
        self.lineEdit_2.setGeometry(QtCore.QRect(460, 340, 231, 20))
        self.lineEdit_2.setStyleSheet("font-family:微软雅黑;\n"
"background:transparent;\n"
"border:-1px;")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label_7 = QtWidgets.QLabel(self)
        self.label_7.setGeometry(QtCore.QRect(460, 310, 231, 1))
        self.label_7.setStyleSheet("background:gray;")
        self.label_7.setText("")
        self.label_7.setObjectName("label_7")
        self.label_8 = QtWidgets.QLabel(self)
        self.label_8.setGeometry(QtCore.QRect(460, 360, 231, 1))
        self.label_8.setStyleSheet("background:gray;")
        self.label_8.setText("")
        self.label_8.setObjectName("label_8")
        self.pushButton_16 = QtWidgets.QPushButton(self)
        self.pushButton_16.setGeometry(QtCore.QRect(660, 280, 31, 31))
        self.pushButton_16.setStyleSheet("background:rgb(0, 0, 0, 0)")
        self.pushButton_16.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("Tim\down.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_16.setIcon(icon)
        self.pushButton_16.setObjectName("pushButton_16")
        self.checkBox = QtWidgets.QCheckBox(self)
        self.checkBox.setGeometry(QtCore.QRect(450, 470, 71, 16))
        self.checkBox.setStyleSheet("background:rgb(0, 0, 0, 0);\n"
"color:gray;\n"
"font-family:微软雅黑;")
        self.checkBox.setObjectName("checkBox")
        self.checkBox_2 = QtWidgets.QCheckBox(self)
        self.checkBox_2.setGeometry(QtCore.QRect(450, 500, 71, 16))
        self.checkBox_2.setStyleSheet("background:rgb(0, 0, 0, 0);\n"
"color:gray;\n"
"font-family:微软雅黑;")
        self.checkBox_2.setObjectName("checkBox_2")
        self.pushButton_17 = QtWidgets.QPushButton(self)
        self.pushButton_17.setGeometry(QtCore.QRect(590, 468, 81, 20))
        self.pushButton_17.setStyleSheet("background:rgb(0, 0, 0, 0);\n"
"color:gray;\n"
"font-family:微软雅黑;")
        self.pushButton_17.setObjectName("pushButton_17")
        self.pushButton_18 = QtWidgets.QPushButton(self)
        self.pushButton_18.setGeometry(QtCore.QRect(590, 498, 81, 20))
        self.pushButton_18.setStyleSheet("background:rgb(0, 0, 0, 0);\n"
"color:gray;\n"
"font-family:微软雅黑;")
        self.pushButton_18.setObjectName("pushButton_18")
        self.pushButton_19 = QtWidgets.QPushButton(self)
        self.pushButton_19.setGeometry(QtCore.QRect(670, 370, 21, 21))
        self.pushButton_19.setStyleSheet("background:rgb(0, 0, 0, 0)")
        self.pushButton_19.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("ewm.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_19.setIcon(icon1)
        self.pushButton_19.setIconSize(QtCore.QSize(25, 25))
        self.pushButton_19.setObjectName("pushButton_19")
        self.pushButton_3 = QtWidgets.QPushButton(self)
        self.pushButton_3.setGeometry(QtCore.QRect(650, 62, 21, 21))
        self.pushButton_3.setStyleSheet("QPushButton{\n"
"    color:Gray;\n"
"    font-family:微软雅黑;\n"
"    border:1px;\n"
"    background:transparent;\n"
"}\n"
"QPushButton:hover{\n"
"    background:rgb(169, 169, 169, 90);\n"
"}\n"
"QPushButton:pressed{\n"
"    background:rgb(169, 169, 169, 120);\n"
"}")
        self.pushButton_3.setText("")
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("Tim\setting.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_3.setIcon(icon2)
        self.pushButton_3.setIconSize(QtCore.QSize(30, 30))
        self.pushButton_3.setObjectName("pushButton_3")
        self.pushButton = QtWidgets.QPushButton(self)
        self.pushButton.setGeometry(QtCore.QRect(680, 60, 25, 25))
        self.pushButton.setStyleSheet("QPushButton{\n"
"    color:Gray;\n"
"    font-family:微软雅黑;\n"
"    border:1px;\n"
"    background:transparent;\n"
"}\n"
"QPushButton:hover{\n"
"    background:rgb(169, 169, 169, 90);\n"
"}\n"
"QPushButton:pressed{\n"
"    background:rgb(169, 169, 169, 120);\n"
"}")
        self.pushButton.setText("")
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("Tim\close.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton.setIcon(icon3)
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self)
        self.pushButton_2.setGeometry(QtCore.QRect(660, 330, 25, 25))
        self.pushButton_2.setStyleSheet("QPushButton{\n"
"    color:White;\n"
"    font-family:微软雅黑;\n"
"    border: 1px solid DarkGray;\n"
"    border-radius: 12px;\n"
"    background:rgb(255, 255, 255, 60);\n"
"}\n"
"QPushButton:hover{\n"
"    border: 1px solid Gray;\n"
"    background:rgb(255, 255, 255, 90);\n"
"}\n"
"QPushButton:pressed{\n"
"    border: 2px solid DarkGray;\n"
"    background:rgb(255, 255, 255, 30);\n"
"}")
        self.pushButton_2.setText("")
        self.pushButton_2.setIconSize(QtCore.QSize(18, 18))
        self.pushButton_2.setObjectName("pushButton_2")
        self.label_9 = QtWidgets.QLabel(self)
        self.label_9.setGeometry(QtCore.QRect(665, 335, 14, 15))
        self.label_9.setText("")
        self.label_9.setPixmap(QtGui.QPixmap("Tim\jt.png"))
        self.label_9.setScaledContents(True)
        self.label_9.setObjectName("label_9")
        self.pushButton_4 = QtWidgets.QPushButton(self)
        self.pushButton_4.setGeometry(QtCore.QRect(480, 170, 61, 61))
        self.pushButton_4.setStyleSheet("QPushButton{\n"
"    color:White;\n"
"    font-family:微软雅黑;\n"
"    border-radius: 30px;\n"
"    background:rgb(255, 255, 255, 60);\n"
"}\n"
"QPushButton:hover{\n"
"    background:rgb(255, 255, 255, 90);\n"
"}\n"
"QPushButton:pressed{\n"
"    background:rgb(255, 255, 255, 30);\n"
"}")
        self.pushButton_4.setText("")
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap("Tim\QQ.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_4.setIcon(icon4)
        self.pushButton_4.setIconSize(QtCore.QSize(60, 60))
        self.pushButton_4.setObjectName("pushButton_4")
        self.pushButton_5 = QtWidgets.QPushButton(self)
        self.pushButton_5.setGeometry(QtCore.QRect(605, 170, 61, 61))
        self.pushButton_5.setStyleSheet("QPushButton{\n"
"    color:White;\n"
"    font-family:微软雅黑;\n"
"    border-radius: 30px;\n"
"    background:rgb(255, 255, 255, 60);\n"
"}\n"
"QPushButton:hover{\n"
"    background:rgb(255, 255, 255, 90);\n"
"}\n"
"QPushButton:pressed{\n"
"    background:rgb(255, 255, 255, 30);\n"
"}")
        self.pushButton_5.setText("")
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap("Tim\微信.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.pushButton_5.setIcon(icon5)
        self.pushButton_5.setIconSize(QtCore.QSize(60, 60))
        self.pushButton_5.setObjectName("pushButton_5")
        self.label.raise_()
        self.label_2.raise_()
        self.label_4.raise_()
        self.label_6.raise_()
        self.lineEdit.raise_()
        self.lineEdit_2.raise_()
        self.label_7.raise_()
        self.label_8.raise_()
        self.pushButton_16.raise_()
        self.checkBox.raise_()
        self.checkBox_2.raise_()
        self.pushButton_17.raise_()
        self.pushButton_18.raise_()
        self.pushButton_19.raise_()
        self.pushButton_3.raise_()
        self.pushButton.raise_()
        self.label_9.raise_()
        self.pushButton_2.raise_()
        self.pushButton_4.raise_()
        self.pushButton_5.raise_()
        self.retranslateUi(self)
        QtCore.QMetaObject.connectSlotsByName(self)
    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label_4.setText(_translate("Form", "QQ登录"))
        self.label_6.setText(_translate("Form", "微信登录"))
        self.lineEdit.setPlaceholderText(_translate("Form", "账号"))
        self.lineEdit_2.setPlaceholderText(_translate("Form", "密码"))
        self.checkBox.setText(_translate("Form", "记住密码"))
        self.checkBox_2.setText(_translate("Form", "自动登录"))
        self.pushButton_17.setText(_translate("Form", "找回密码"))
        self.pushButton_18.setText(_translate("Form", "注册账号"))
        self.pushButton_4.clicked.connect(self.QQ)
        self.pushButton_5.clicked.connect(self.Wx)
    def QQ(self):
        global QQ
        if QQ == 0:
            QQ = 1
            icon4 = QtGui.QIcon()
            icon4.addPixmap(QtGui.QPixmap("Tim\QQ.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.pushButton_4.setIcon(icon4)
            self.pushButton_4.setIconSize(QtCore.QSize(60, 60))
            icon5 = QtGui.QIcon()
            icon5.addPixmap(QtGui.QPixmap(r"Tim\微信.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.pushButton_5.setIcon(icon5)
            self.pushButton_5.setIconSize(QtCore.QSize(60, 60))
            self.label_4.setStyleSheet("font-family:微软雅黑;\n""color:#1191FF;")
            self.label_6.setStyleSheet("font-family:微软雅黑;\n""color:#A6A6A6;")
    def Wx(self):
        global QQ
        if QQ == 1:
            QQ = 0
            icon4 = QtGui.QIcon()
            icon4.addPixmap(QtGui.QPixmap(r"Tim\QQ_.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.pushButton_4.setIcon(icon4)
            self.pushButton_4.setIconSize(QtCore.QSize(60, 60))
            icon5 = QtGui.QIcon()
            icon5.addPixmap(QtGui.QPixmap(r"Tim\微信_.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.pushButton_5.setIcon(icon5)
            self.pushButton_5.setIconSize(QtCore.QSize(60, 60))
            self.label_4.setStyleSheet("font-family:微软雅黑;\n""color:#A6A6A6;")
            self.label_6.setStyleSheet("font-family:微软雅黑;\n""color:#17C444;")
    def mousePressEvent(self, e):
        if e.button() == Qt.LeftButton:
            self.m_drag = True
            self.m_DragPosition = e.globalPos() - self.pos()
            e.accept()
    def mouseReleaseEvent(self, e):
        if e.button() == Qt.LeftButton:
            self.m_drag = False
    def mouseMoveEvent(self, e):
        try:
            if Qt.LeftButton and self.m_drag:
                self.move(e.globalPos() - self.m_DragPosition)
                e.accept()
        except:
            print("错误代码:000x0")
def main():
    app = QtWidgets.QApplication(sys.argv)
    gui = Tim()
    gui.show()
    sys.exit(app.exec_())
if __name__ == '__main__':
    main()

Qt直接生成的导致代码结构比较臃肿没有时间优化了。

你可能感兴趣的:(PyQt5 Tim界面 开源)