Python/pyqt5/CODE/qt05x範例程式/qt05_thread01.py
2024-06-27 15:41:10 +08:00

51 lines
883 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
'''
【簡介】
PyQT5中QThread範例
'''
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
global sec
sec=0
def setTime():
global sec
sec+=1
# LED顯示數字+1
lcdNumber.display(sec)
def work():
# 計時器每秒計數
timer.start(1000)
for i in range(2000000000):
pass
timer.stop()
if __name__ == "__main__":
app = QApplication(sys.argv)
top = QWidget()
top.resize(300,120)
# 垂直佈局類別
layout = QVBoxLayout(top)
# 增加一個顯示面板
lcdNumber = QLCDNumber()
layout.addWidget(lcdNumber)
button=QPushButton("測試")
layout.addWidget(button)
timer = QTimer()
# 每次計時結束觸發setTime
timer.timeout.connect(setTime)
button.clicked.connect(work)
top.show()
sys.exit(app.exec_())