一、运行窗口基本案例
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtGui import QIcon
import sys
from threading import Thread
from UI import Ui_MainWindow
class Win(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setFixedSize(self.width(), self.height())
self._translate = QtCore.QCoreApplication.translate
self.setWindowTitle(self._translate("MainWindow", "软件名"))
self.setWindowIcon(QIcon('logo.png'))
@staticmethod
def main():
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QtWidgets.QApplication(sys.argv)
UI = Win()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
Win.main()
二、运行窗口案例二
from PyQt5 import QtCore,QtWidgets
from PyQt5.QtGui import QIcon
from openpyxl import Workbook
import sys
from threading import Thread
from UIPy import login
class Win(QtWidgets.QMainWindow, login.Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setFixedSize(self.width(), self.height())
self.setWindowIcon(QIcon('deer.png'))
self.Button()
self.directory = None
def Button(self):
self.按钮对象.clicked.connect(self.短时间功能1)
self.pushButton1.clicked.connect(self.短时间功能2)
self.pushButton2.clicked.connect(self.长时间功能)
def 短时间功能1(self):
self.directory = QtWidgets.QFileDialog.getExistingDirectory(None, "选取文件夹", "C:/")
self.lineEdit.setText(self.directory)
def 短时间功能2(self):
txt_file = QtWidgets.QFileDialog.getOpenFileName(None, '选择要采集的txt文件', "C:/",
filter='*.txt')
if '.txt' not in txt_file[0]:
self.textEdit.append('错误!选择非txt文件!!')
else:
self.txt_frame.setText(txt_file[0])
self.pick_txt = txt_file[0]
def start(self):
user = self.user_input.text()
psw = self.psw_input.text()
pass
def 长时间功能(self):
"""
需要开启线程完成
:return:
"""
mT = Thread(target=self.start)
mT.setDaemon(True)
mT.start()
def main():
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QtWidgets.QApplication(sys.argv)
UI = Win()
UI.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()