Displaying numbers with QLCDNumber.display() with PyQt5
-
wrote on 25 Aug 2018, 08:52 last edited by
I am bit new to Qt and python. I have created a simple GUI which consist of a simple calculator. I used the QT Designer to design the GUI and now I want to link my buttons to the QLCDNumber display.
I created a *.clicked.connect(self.my_func) to link it but only the print statement is working well when clicking the button.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
self.gridLayoutWidget = QtWidgets.QWidget(Dialog)
self.gridLayoutWidget.setGeometry(QtCore.QRect(20, 80, 164, 134))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")self.pushButton_9 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_9.setObjectName("pushButton_9") self.gridLayout.addWidget(self.pushButton_9, 0, 2, 1, 1) self.pushButton_9.clicked.connect(self.my_func) self.pushButton_5 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_5.setObjectName("pushButton_5") self.gridLayout.addWidget(self.pushButton_5, 1, 1, 1, 1) self.pushButton_7 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_7.setObjectName("pushButton_7") self.gridLayout.addWidget(self.pushButton_7, 0, 0, 1, 1) self.pushButton_6 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_6.setObjectName("pushButton_6") self.gridLayout.addWidget(self.pushButton_6, 1, 2, 1, 1) self.pushButton_8 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_8.setObjectName("pushButton_8") self.gridLayout.addWidget(self.pushButton_8, 0, 1, 1, 1) self.pushButton_4 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_4.setObjectName("pushButton_4") self.gridLayout.addWidget(self.pushButton_4, 1, 0, 1, 1) self.pushButton_3 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_3.setObjectName("pushButton_3") self.gridLayout.addWidget(self.pushButton_3, 2, 2, 1, 1) self.pushButton_0 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_0.setObjectName("pushButton_0") self.gridLayout.addWidget(self.pushButton_0, 3, 0, 1, 3) self.pushButton_2 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_2.setObjectName("pushButton_2") self.gridLayout.addWidget(self.pushButton_2, 2, 1, 1, 1) self.pushButton_1 = QtWidgets.QPushButton(self.gridLayoutWidget) self.pushButton_1.setObjectName("pushButton_1") self.gridLayout.addWidget(self.pushButton_1, 2, 0, 1, 1) self.pushButton_6.raise_() self.pushButton_5.raise_() self.pushButton_4.raise_() self.pushButton_1.raise_() self.pushButton_2.raise_() self.pushButton_3.raise_() self.pushButton_8.raise_() self.pushButton_9.raise_() self.pushButton_0.raise_() self.pushButton_7.raise_() self.lcdNumber = QtWidgets.QLCDNumber(Dialog) self.lcdNumber.setGeometry(QtCore.QRect(20, 10, 221, 61)) self.lcdNumber.setObjectName("lcdNumber") self.gridLayoutWidget_2 = QtWidgets.QWidget(Dialog) self.gridLayoutWidget_2.setGeometry(QtCore.QRect(190, 80, 51, 134)) self.gridLayoutWidget_2.setObjectName("gridLayoutWidget_2") self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget_2) self.gridLayout_2.setContentsMargins(0, 0, 0, 0) self.gridLayout_2.setObjectName("gridLayout_2") self.pushButton_10 = QtWidgets.QPushButton(self.gridLayoutWidget_2) self.pushButton_10.setObjectName("pushButton_10") self.gridLayout_2.addWidget(self.pushButton_10, 2, 0, 1, 1) self.pushButton = QtWidgets.QPushButton(self.gridLayoutWidget_2) self.pushButton.setObjectName("pushButton") self.gridLayout_2.addWidget(self.pushButton, 1, 0, 1, 1) self.pushButton_11 = QtWidgets.QPushButton(self.gridLayoutWidget_2) self.pushButton_11.setObjectName("pushButton_11") self.gridLayout_2.addWidget(self.pushButton_11, 3, 0, 1, 1) self.pushButton_12 = QtWidgets.QPushButton(self.gridLayoutWidget_2) self.pushButton_12.setObjectName("pushButton_12") self.gridLayout_2.addWidget(self.pushButton_12, 0, 0, 1, 1) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(20, 230, 60, 16)) self.label.setObjectName("label") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def my_func(self): print("Works") self.lcdNumber.display(9) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.pushButton_9.setText(_translate("Dialog", "9")) self.pushButton_5.setText(_translate("Dialog", "5")) self.pushButton_7.setText(_translate("Dialog", "7")) self.pushButton_6.setText(_translate("Dialog", "6")) self.pushButton_8.setText(_translate("Dialog", "8")) self.pushButton_4.setText(_translate("Dialog", "4")) self.pushButton_3.setText(_translate("Dialog", "3")) self.pushButton_0.setText(_translate("Dialog", "0")) self.pushButton_2.setText(_translate("Dialog", "2")) self.pushButton_1.setText(_translate("Dialog", "1")) self.pushButton_10.setText(_translate("Dialog", "-")) self.pushButton.setText(_translate("Dialog", "+")) self.pushButton_11.setText(_translate("Dialog", "=")) self.pushButton_12.setText(_translate("Dialog", "DEL")) self.label.setText(_translate("Dialog", "TextLabel"))
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_()) -
Hi and welcome to devnet,
What version of Python and PyQt are you using ?
Just tested here and clicking on the button 9 shows the number 9 on the LCD widget.
wrote on 25 Aug 2018, 13:13 last edited by@SGaist said in Displaying numbers with QLCDNumber.display() with PyQt5:
ed here and click
Hey thanks for the fast reply ;)
I'm using Python 3.6.3 and PyQt5 (5.11.2)
The problem i found now is that
self.lcdNumber.display(9)
doesn't display the number on the display for some unknown reason. I found a workaround with repaint:
self.lcdNumber.display(9) self.lcdNumber.repaint()
Now it works. Maybe a reason for this is that I'm using macOs instead of windows. QT sometimes has different solutions for macOs as far as i can say.
-
Hi and welcome to devnet,
What version of Python and PyQt are you using ?
Just tested here and clicking on the button 9 shows the number 9 on the LCD widget.
-
Hi and welcome to devnet,
What version of Python and PyQt are you using ?
Just tested here and clicking on the button 9 shows the number 9 on the LCD widget.
wrote on 25 Aug 2018, 13:13 last edited by@SGaist said in Displaying numbers with QLCDNumber.display() with PyQt5:
ed here and click
Hey thanks for the fast reply ;)
I'm using Python 3.6.3 and PyQt5 (5.11.2)
The problem i found now is that
self.lcdNumber.display(9)
doesn't display the number on the display for some unknown reason. I found a workaround with repaint:
self.lcdNumber.display(9) self.lcdNumber.repaint()
Now it works. Maybe a reason for this is that I'm using macOs instead of windows. QT sometimes has different solutions for macOs as far as i can say.
-
How did you install PyQt5 ?
It should not make a difference in this case. Note that I also tested on macOS.
-
How did you install PyQt5 ?
It should not make a difference in this case. Note that I also tested on macOS.
wrote on 25 Aug 2018, 14:41 last edited byI used this link:
https://www.riverbankcomputing.com/software/pyqt/download5where i also downloades SIP:
https://www.riverbankcomputing.com/software/sip/download -
What version of macOS are you using ?
Did you build PyQt5 yourself ? If so, how did you install Qt ?
In any case, can you try the version coming from pip ?
-
What version of macOS are you using ?
Did you build PyQt5 yourself ? If so, how did you install Qt ?
In any case, can you try the version coming from pip ?
wrote on 26 Aug 2018, 08:11 last edited bymacOs High Sierra (10.13.6)
I installed via pip (pip3)
maett@Matthiass-MacBook-Pro-2:~/PyQt$ pip install pyqt5 Requirement already satisfied: pyqt5 in /Users/maett/anaconda3/lib/python3.6/site-packages (5.11.2) Requirement already satisfied: PyQt5_sip<4.20,>=4.19.11 in /Users/maett/anaconda3/lib/python3.6/site-packages (from pyqt5) (4.19.12)
Why are there differences between a Windows menu bar and a macOS one to program?
I thought QT should be system independent?
Do u know good tutorials combining Qt with OpenCV? -
Except that you have the conda version of the package installed... So right know, which version are you using ?
Because both OS does thing differently. Qt goal has always been to provide you with a common code base that behaves according to the OS your application is running on. You can find more information about that in QMenuBar's documentation.
You can check that small introduction for OpenCV and Qt
-
Except that you have the conda version of the package installed... So right know, which version are you using ?
Because both OS does thing differently. Qt goal has always been to provide you with a common code base that behaves according to the OS your application is running on. You can find more information about that in QMenuBar's documentation.
You can check that small introduction for OpenCV and Qt
wrote on 27 Aug 2018, 19:36 last edited by@SGaist
Im not sure if i get the question. I've installed python (3.6.3) via conda and downloaded pyqt5 & sip from riverbank.
After installation i checked if it is installed viapip install pyqt5
Are there any problems with the conda version of python and Qt? '
Thank u soooo much for the links :)
-
Since you're using conda, try installing the version that is provided through conda, that will make your environment more coherent.
1/10