Python Forum
Help to make a shuffleboard scoreboard
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help to make a shuffleboard scoreboard
#1
Hello!

Im a totally newbie at this (as you will notice), but i am trying to use a Raspberry Pi and a TV-screen to make a scoreboard for my shuffleboard.
I've used QT-designer to make GUI, and gpiozero to make a scorecounter. Each of them are working alone, but when im trying to put them together noting happens ( the GUI pops up, but i cant change the values in the LCD numbers) It should work like this: I have three physical buttons, when i press button1 it should add a point for team number1, when i press button3 it should add a point for team number2 and when i press button2 it should reset both counters.

My code looks like this: Does anyone have tips to what im doing wrong?

from gpiozero import Button
from time import sleep
from PyQt5 import QtCore, QtGui, QtWidgets

count = 0
count1 = 0

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.lcdNumber = QtWidgets.QLCDNumber(self.centralWidget)
        self.lcdNumber.setGeometry(QtCore.QRect(60, 240, 121, 111))
        self.lcdNumber.setObjectName("lcdNumber")
        self.lcdNumber_2 = QtWidgets.QLCDNumber(self.centralWidget)
        self.lcdNumber_2.setGeometry(QtCore.QRect(620, 240, 121, 111))
        self.lcdNumber_2.setObjectName("lcdNumber_2")
        self.label = QtWidgets.QLabel(self.centralWidget)
        self.label.setGeometry(QtCore.QRect(7, 11, 791, 581))
        self.label.setText("")
        self.label.setPixmap(QtGui.QPixmap("../Pictures/ulven.jpg"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")
        self.label.raise_()
        self.lcdNumber.raise_()
        self.lcdNumber_2.raise_()
        MainWindow.setCentralWidget(self.centralWidget)
        self.lcdNumber.display(count)
        self.lcdNumber_2.display(count1)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
    



button1 = Button(2)
button2 = Button(3)
button3 = Button(4)

while True:
    if button3.is_pressed:
        count += 1
        sleep(0.4)
    if button1.is_pressed:
        count1 += 1
        sleep(0.4)
    elif button2.is_pressed:
        count = 0
        count1 = 0
Larz60+ write Apr-28-2022, 06:33 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply
#2
Please wrap code in Python tags.

app.exec_() blocks program execution until the GUI is closed.

sys.exit(app.exec_()) exits the program as soon as this happens.

This is never executed:
button1 = Button(2)
button2 = Button(3)
button3 = Button(4)

while True:
    if button3.is_pressed:
        count += 1
        sleep(0.4)
    if button1.is_pressed:
        count1 += 1
        sleep(0.4)
    elif button2.is_pressed:
        count = 0
        count1 = 0
Read up on QTimer to see how you can run your GUI and run your hardware code simultaneously.

Using a sleep(0.4) to prevent a button press from being counted as multiple presses is not reliable. You never want to use the sleep() command in a gui application. It makes the GUI unresponsive.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Object of type Scoreboard is not JSON serializable lsepolis123 9 9,466 Aug-13-2019, 11:22 AM
Last Post: lsepolis123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020