PyQt5学习笔记3

timer

    def set_ui(self):
        layout=QBoxLayout(QBoxLayout.TopToBottom)
        lb=QLabel('Hello World !',self)
        self.lcd=QLCDNumber(self)
        self.lcd.setDigitCount(20)
        self.lcd.setMode(QLCDNumber.Dec)
        self.lcd.setStyleSheet('background-color:green;border:1px solid black;')
        layout.addWidget(lb)
        layout.addWidget(self.lcd)
        time=QTimer(self)
        time.setInterval(1000)
        time.timeout.connect(self.refresh)
        time.start()
        self.setLayout(layout)

    def refresh(self):
        startDate = QDateTime.currentMSecsSinceEpoch()
        endDate=QDateTime(QDate(2021,2,4),QTime(0,0,0)).toMSecsSinceEpoch()
        interval=endDate-startDate
        if interval>0:
            days=interval//(24*60*60*1000)
            hour=(interval-days*24*60*60*1000)//(60*60*1000)
            min = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000) // (60 * 1000)
            sec = (interval - days * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) // 1000
            intervals = str(days) + ':' + str(hour) + ':' + str(min) + ':' + str(sec)
            self.lcd.display(intervals)

stackWidget

    def tab1UI(self):
        widget1=QWidget()

        widget2=QWidget()
        widget3=QWidget()

        widget1.setStyleSheet('background-color:red;')
        widget2.setStyleSheet('background-color:yellow;')
        widget3.setStyleSheet('background-color:green;')
        stackwidget=QStackedWidget()
        stackwidget.addWidget(widget1)
        stackwidget.addWidget(widget2)
        stackwidget.addWidget(widget3)
        layout=QVBoxLayout()
        layout.addWidget(stackwidget)
        self.setLayout(layout)
        pageComboBox=QComboBox(self)
        pageComboBox.addItems(['page 1','page 2','page 3'])
        pageComboBox.activated[int].connect(stackwidget.setCurrentIndex)

你可能感兴趣的:(pyqt5,python)