import time
from PySide6.QtWidgets import *
from PySide6.QtCore import *
meutex = QMutex()
class MyThread(QThread):
def __init__(self):
super().__init__()
def run(self):
meutex.lock()
values = [1,2,3,4,5,6,7]
for i in values:
print(i)
time.sleep(0.3)
meutex.unlock()
class MyThread2(QThread):
def __init__(self):
super().__init__()
def run(self):
meutex.lock()
values = [ "a","b","c","d","e"]
for i in values:
print(i)
time.sleep(0.2)
meutex.unlock()
class Window(QWidget):
def __init__(self):
super().__init__()
self.btn1 = QPushButton("按鈕1",self)
self.btn2 = QPushButton("按鈕2",self)
self.btn1.setGeometry(30,30,80,40)
self.btn2.setGeometry(130,30,80,40)
#創(chuàng)建子線程
self.t1 = MyThread()
self.t2 = MyThread2()
#slots
self.btn1.clicked.connect(self.onBtn1Click)
self.btn2.clicked.connect(self.onBtn2Click)
def onBtn1Click(self):
self.t1.start()
self.t2.start()
def onBtn2Click(self):
self.t2.start()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec())
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。