I have written a programme which can control a PWM output on a raspberry pi from the command line but I would now like to control it using a GUI.
I am designing the GUI using PyQt5 to control a PWM output, I would like to retrieve the value from the Label which is adjusted with a dial to then be used to Change the duty cycle of my PWM output.
I am using a raspberry pi 3 Model B+.
I have attached the relevant section of my code below:
Setting up of the Main Window - standard ui to py conversion that happens when using pyuic.
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.dial = QtWidgets.QDial(self.centralwidget)
self.dial.setObjectName("dial")
self.verticalLayout.addWidget(self.dial)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.dial.valueChanged['int'].connect(self.label.setNum)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
Function which is trying to retrieve the value from the label and ultimately update the duty cycle.
def ChangeSpeed(self):
self.My_PWM.start(0)
while True:
if 0 < self.ui.label:
self.My_PWM.ChangeDutyCycle(self.ui.label)
elif self.ui.label<0:
self.My_PWM.ChangeDutyCycle(0)
print("Programme Ended")
break
I get a type error: unorderable tyoes int()
This question is not just straight forward conversion as it does not allow be to convert he QLabel Value to an integer.
Thanks!