On the Rasberry Pi, place the LCD Number using Qt Desinger
We are working on creating a GUI application like the one shown below with Python 3.5.3.
I want to do the following two things.
・ After pressing the START button, the LCD Number value is updated every arbitrary time.
・ Stop with STOP button
I created the following code,
It does not work as intended.
Since I've just started studying python, it's not enough to study,
I'm sorry, can you give me some advice?
#-*-coding: utf-8-*- # Form implementation generated from reading ui file 'main.ui' # # Created by: PyQt5 UI code generator 5.11.2 # # WARNING! All changes made in this file will be lost! import time from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog (object): def setupUi (self, Dialog): Dialog.setObjectName ("Dialog") Dialog.resize (400, 300) font = QtGui.QFont () font.setPointSize (14) Dialog.setFont (font) self.buttonBox = QtWidgets.QDialogButtonBox (Dialog) self.buttonBox.setGeometry (QtCore.QRect (30, 240, 341, 32)) self.buttonBox.setOrientation (QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons (QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Ok) self.buttonBox.setObjectName ("buttonBox") self.lcdNumber = QtWidgets.QLCDNumber (Dialog) self.lcdNumber.setGeometry (QtCore.QRect (90, 60, 91, 51)) self.lcdNumber.setAutoFillBackground (True) self.lcdNumber.setObjectName ("lcdNumber") self.pushButton = QtWidgets.QPushButton (Dialog) self.pushButton.setGeometry (QtCore.QRect (230, 70, 100, 40)) self.pushButton.setObjectName ("pushButton") self.pushButton_2 = QtWidgets.QPushButton (Dialog) self.pushButton_2.setGeometry (QtCore.QRect (230, 130, 100, 40)) self.pushButton_2.setObjectName ("pushButton_2") self.actionOnStart = QtWidgets.QAction (Dialog) self.actionOnStart.setObjectName ("actionOnStart") self.actionOnStop = QtWidgets.QAction (Dialog) self.actionOnStop.setObjectName ("actionOnStop") self.retranslateUi (Dialog) self.buttonBox.accepted.connect (Dialog.accept) self.buttonBox.rejected.connect (Dialog.reject) self.pushButton.clicked.connect (self.OnStart) self.pushButton_2.clicked.connect (self.OnStop) QtCore.QMetaObject.connectSlotsByName (Dialog) def retranslateUi (self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle (_translate ("Dialog", "Dialog")) self.pushButton.setText (_translate ("Dialog", "START")) self.pushButton_2.setText (_translate ("Dialog", "STOP")) self.actionOnStart.setText (_translate ("Dialog", "OnStart")) self.actionOnStop.setText (_translate ("Dialog", "OnStop")) def OnStart (self): i = 0 while True: i = i + 1 self.lcdNumber.display (i) time.sleep (1) def OnStop (self): print ('I don't know the code after pressing the Stop button') if __name__ == "__main__": import sys app = QtWidgets.QApplication (sys.argv) Dialog = QtWidgets.QDialog () ui = Ui_Dialog () ui.setupUi (Dialog) Dialog.show () sys.exit (app.exec _ ())
Answer # 1
If you write a loop, the process will stop there, so use a timer.
def __init __ (self): self._timer = QtCore.QTimer () self._timer.timeout.connect (self.run) def on_start (self): self._timer.start (1000) def run (self): self._lcd_number.display ( self._lcd_number.intValue () + 1 ) self._timer.start (1000) def on_stop (self): self._timer.stop ()
The name of the object is changed.
- python 3x - about iterative processing when the number of data of python scraping destination is unknown
- python - multiple display of random number graph
- python - [django] implementation of the number of views
- python 3x - table not created in sqlalchemy
- python - about the value acquired by for sentence
- python - [tkinter] i want to set the initial value of paned window
- i want to write a number guessing program that uses endless loop using break in python
- python - i want to write the value at each x of f(x) to txt
- i want to store a unicode escape value in a dictionary type value in python
- mass random number generation speed in python
- [python] how to obtain a substitution value such that determinant=0
- python missing value removal
- python - image recognition using the created cascade classifier
- python - if the specified number is contained in one of the tuple elements, the other numbers will be added to the set
- python - the number of clusters found in image classification using the xmeans method is strange
- python - how to select a specific number by default at startup in treeview of tkinter
- when writing a yaml file read by python, i want to prevent the value from being changed
- python 3x - count the number of elements separated by commas
- i want to process the numerical value (str) received from arduino with python
- python - i want to run the nfcpy sample program "tagtoolpy" on raspberry pi
- python - i want to turn on the leds randomly on the raspberry pi
- python - i would like to know the reason why the circuit becomes 0v when the circuit is turned on in the raspberry pi
- python - couldn't connect to display :00
- python - raspberry pi 4 i want to perform serial communication simultaneously with 1 and 2 windows pcs
- python - i can ssh ping with my raspberry pi but it doesn't connect to the internet
- python - cannot move files to /opt