0
QLCDNumber의 값을 업데이트하려고합니다. 내가 할 수 있기를 원하는 것은 값을 출력하는 별도의 스레드에서 함수를 실행하는 것입니다.이 경우에는 위쪽으로 세고이 값을 화면에 표시합니다. 여기 Python에서 QLCDNumber를 증가시키는 방법
내가 사용하고있는 파이썬 스크립트이며, 그 이하로합니다 (QLCDNumber는 "DISP"이름을 붙일 수있다) .ui 파일의 내용입니다 :import sys
import threading
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
from time import sleep
Ui_MainWindow, QtBaseClass = uic.loadUiType("./disp.ui")
class MainWindow(QMainWindow, Ui_MainWindow):
counter = pyqtSignal(int)
counting = False
def __init__(self):
QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.disp.display(?????) #<----
def startCounting(self):
if not self.counting:
self.counting = True
thread = threading.Thread(target=self.something)
thread.start()
def something(self):
for i in range(100):
self.counter.emit(int(i))
sleep(0.5)
self.counting = False
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
.ui 파일 :
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>577</width>
<height>504</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLCDNumber" name="disp"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>577</width>
<height>24</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
제안한 추가 기능을 추가하려고했지만 여전히 작동하지 않습니다. 필요한 다른 단계가 있습니까? 현재 카운터가 제로에 있습니다 (플러스에서는 제대로로드됩니다)? –
'startCounting'기능을 트리거하는 버튼이 있습니까? 그렇지 않으면 뭔가를보기 위해'__init__'에서이 함수를 실행할 필요가 없습니다. 답변의 코드에 주석 처리 된 코드를 추가하여 주석 처리를 취소하면 실제 동작을 볼 수 있습니다. – SyedElec
도움 주셔서 감사합니다. –