is there any way to use timer object to set text in pyqt5 with out creating another function to get the time to upsate or is there any alternative way to update the text set in a label
import sys from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow from PyQt5.QtWidgets import QVBoxLayout, QLabel from PyQt5.QtGui import QFont from PyQt5.QtCore import QTimer, QTime, Qt from PyQt5 import QtCore class Window(QWidget): def __init__(self): super().__init__() self.build_time() self.show() self.showFullScreen() self.setStyleSheet("background-color: black;") def keyPressEvent(self, e): if e.key() == QtCore.Qt.Key_Escape: self.close() if e.key() == QtCore.Qt.Key_F11: if self.isMaximized(): self.showNormal() else: self.showMaximized() font = "Arial" color = "antiquewhite" style_sheet = f"color: {color} ;" def build_time(self): self.time = QLabel(self) self.time.setGeometry(0, 85, 400, 75) self.time.setStyleSheet(self.style_sheet) self.time.setFont(QFont(self.font, 60)) timer = QTimer(self) # adding action to timer timer.timeout.connect(self.showTime) # update the timer every second timer.start(1000) def showTime(self): # getting current time current_time = QTime.currentTime() # converting QTime object to string label_time = current_time.toString('hh:mm:ss') # showing it to the label self.time.setText(label_time) # create pyqt5 app App = QApplication(sys.argv) # create the instance of our Window window = Window() # showing all the widgets window.show() # start the app App.exit(App.exec_())
buran write Jan-12-2021, 05:00 AM:
Please, post in correct sub-forum. This time I moved it to GUI.
Please, post in correct sub-forum. This time I moved it to GUI.