Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyqt5 layout
#2
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_())
Reply


Messages In This Thread
pyqt5 layout - by Nickd12 - Jan-12-2021, 03:06 AM
RE: pyqt5 layout - by Axel_Erfurt - Jan-12-2021, 09:26 AM
RE: pyqt5 layout - by deanhystad - Jan-12-2021, 04:35 PM
RE: pyqt5 layout - by Nickd12 - Jan-12-2021, 11:20 PM
RE: pyqt5 layout - by Nickd12 - Jan-12-2021, 11:26 PM
RE: pyqt5 layout - by deanhystad - Jan-13-2021, 03:38 AM
RE: pyqt5 layout - by Nickd12 - Jan-13-2021, 04:07 AM
RE: pyqt5 layout - by deanhystad - Jan-18-2021, 04:45 AM
RE: pyqt5 layout - by Axel_Erfurt - Jan-18-2021, 09:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyQt5 Relative Layout Unkovic 1 655 Nov-10-2023, 01:52 PM
Last Post: Axel_Erfurt
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,861 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  Python GUI layout off between different OS shift838 5 3,760 Jan-02-2019, 02:53 AM
Last Post: shift838
  PyQt5: Add Variable Number of Rows to Layout Based on Python Dictionary kennybassett 2 4,786 Oct-02-2018, 02:05 PM
Last Post: Alfalfa
  [Tkinter] grid layout neech 8 17,796 Oct-14-2016, 07:06 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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