pyside6 常用窗口界面模板
start
- 今天整理一下我使用次数最多的 pyside6 代码模板。
代码
import sys
from Ui_ui import Ui_lookLiveRoom
from PySide6.QtCore import QThread, Signal
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QListWidgetItem,
)
def start_click():
print("异步逻辑")
class WorkerThread(QThread):
updateSignal = Signal(int)
def __init__(self):
super().__init__()
self.parameter = ""
def setParameter(self, parameter):
self.parameter = parameter
def getParameter(self):
return self.parameter
def run(self):
print("传入的参数 " + self.parameter)
if self.parameter == "startClick":
start_click()
self.finished.emit()
class MainWindow(QMainWindow, Ui_lookLiveRoom):
def __init__(self):
super().__init__()
self.setupUi(self)
self.init_change()
self.worker = WorkerThread()
self.worker.finished.connect(self.task_finished)
def init_change(self):
self.setWindowTitle("lazyTomato专属模板")
self.setFixedSize(800, 530)
def task_finished(self):
if self.worker.getParameter() == "startClick":
print("程序结束运行")
def run_script(self):
self.worker.setParameter("startClick")
self.worker.start()
def main():
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
main_window.run_script()
sys.exit(app.exec())
main()