0
QLCDNumberの値を更新しようとしています。私ができるようにしたいのは、値を出力する別のスレッド(この場合は上向きにカウントする)で関数を実行し、この値を画面に表示することです。ここでPythonでQLCDNumberを増やす方法
は、私が使用していますPythonスクリプトであり、その下に(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>
私はあなたが示唆したようにこの余分な機能を追加しようとしましたが、それでも機能しません。カウンターがゼロに座っている瞬間に、必要なステップがもう1つありますか? –
'startCounting'関数をトリガするボタンなどがありますか? もしあなたが何かを見るために '__init__'でこの関数を実行する必要がなければ。私は実際の動作を見るためにコメントを外すことができる答えのコードにコメント付きのコードを追加しました。 – SyedElec
あなたの助けをありがとう –