Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pyqt5 running string and clock stackoverfloww

class Ui_Form(object):
        def setupUi(self, Form):
            Form.setObjectName("Form")
            Form.resize(498, 299)
            self.verticalLayoutWidget = QtWidgets.QWidget(Form)
            self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 479, 281))
            self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
            self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
            self.verticalLayout.setContentsMargins(0, 0, 0, 0)
            self.verticalLayout.setObjectName("verticalLayout")
            self.label_2 = QtWidgets.QLabel(self.verticalLayoutWidget)
            font = QtGui.QFont()
            font.setPointSize(15)
            self.label_2.setFont(font)
            self.label_2.setText("")
            self.label_2.setAlignment(QtCore.Qt.AlignCenter)
            self.label_2.setObjectName("label_2")
            self.verticalLayout.addWidget(self.label_2)
            self.tableWidget = QtWidgets.QTableWidget(self.verticalLayoutWidget)
            self.tableWidget.setObjectName("tableWidget")
            self.tableWidget.setColumnCount(0)
            self.tableWidget.setRowCount(0)
            self.verticalLayout.addWidget(self.tableWidget)
            self.label = QtWidgets.QLabel(self.verticalLayoutWidget)
            font = QtGui.QFont()
            font.setPointSize(15)
            self.label.setFont(font)
            self.label.setObjectName("label")
            self.verticalLayout.addWidget(self.label)

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

        def retranslateUi(self, Form):
            _translate = QtCore.QCoreApplication.translate
            Form.setWindowTitle(_translate("Form", "Form"))
            self.label.setText(_translate("Form", "Running string ... "))


    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        Form = QtWidgets.QWidget()
        ui = Ui_Form()
        ui.setupUi(Form)
        Form.show()
        sys.exit(app.exec_()) ```


main file:

    ``` from PyQt5 import QtWidgets
    from PyQt5.QtCore import QTimer, QTime
    import sys
    import untitled


    class Widget(QtWidgets.QWidget):
        def __init__(self):
            super(Widget, self).__init__()
            self.ui = untitled.Ui_Form()
            self.ui.setupUi(self)

            self.x = 477
            self.y = self.height() - 30
            self.ui.label.move(self.x, self.y)

            self.timer = QTimer(self)
            self.timer.timeout.connect(self.move_label_left)
            self.timer.start(100)

            self.timer2 = QTimer(self)
            self.timer2.timeout.connect(self.show_clock)
            self.timer2.start(1000)

        def move_label_left(self):
            if self.x == -477:
                self.x = 477
                self.x -= 2
                self.ui.label.move(self.x, self.height() - 30)
            else:
                self.x -= 2
                self.ui.label.move(self.x, self.height() - 30)

        def show_clock(self):
            time = QTime.currentTime()
            text = time.toString('hh:mm:ss')
            self.ui.label_2.setText(text)


    app = QtWidgets.QApplication(sys.argv)
    w = Widget()
    w.show()
    sys.exit(app.exec_()) ```
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #running #string #clock #stackoverfloww
ADD COMMENT
Topic
Name
2+2 =