Jan-12-2021, 09:26 AM
self.build_dt = BuildDateTime()
and set it as Widget in mainWindow
self.setCentralWidget(self.build_dt)
from PyQt5.QtCore import (QDate, QTime, Qt, QTimer) from PyQt5.QtGui import QFont from PyQt5.QtWidgets import (QApplication, QMainWindow, QLabel, QWidget) import sys font = "Arial" color = "antiquewhite" style_sheet = f"color: {color} ;" class BuildDateTime(QWidget): def __init__(self): super().__init__() update = QTimer(self) update.timeout.connect(self.show_ui) update.start(1000) # The Time self.time = QLabel(self) self.time.setGeometry(0, 85, 400, 75) self.time.setStyleSheet(style_sheet) self.time.setFont(QFont(font, 60)) # The Date self.date = QLabel(self) self.date.setGeometry(0, 25, 700, 50) self.date.setStyleSheet(style_sheet) self.date.setFont(QFont(font, 30)) def show_ui(self): # Time get_time = QTime.currentTime() time_string = get_time.toString(Qt.DefaultLocaleShortDate) self.time.setText(time_string) # Date now = QDate.currentDate() date_string = now.toString(Qt.DefaultLocaleLongDate) self.date.setText(date_string) class Window(QMainWindow): def __init__(self): super().__init__() self.build_dt = BuildDateTime() self.setCentralWidget(self.build_dt) self.setGeometry(200, 200, 500, 200) #self.show() self.showFullScreen() self.setStyleSheet("background-color: black;") def keyPressEvent(self, e): if e.key() == Qt.Key_Escape: self.close() if e.key() == Qt.Key_F11: if self.isMaximized(): self.showNormal() else: self.showMaximized() if __name__ == '__main__': # 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_())