I have started learning PyQt5 and wanted to create a simple window to test my skills. So I have created this window and I want to receive reviews on any aspect of the code.
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtWidgets import QVBoxLayout,QSplitter, QFormLayout, QLabel, QFrame, QPushButton
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.create_menu_bar()
self.vbox = QVBoxLayout()
self.create_body()
self.show()
def create_menu_bar(self):
title = 'First Porgram'
self.setWindowTitle(title)
self.setGeometry(300, 150, 500, 300)
self.setStyleSheet('background-color:#333;color:#ccc')
self.setFont(QFont('Serif', 10))
self.menu_bar = self.menuBar()
self.file_menu = self.menu_bar.addMenu("File")
self.file_menu.addAction('New')
self.file_menu.addAction('Open')
self.file_menu.addAction('Save')
self.file_menu.addAction('Save as')
self.file_menu.addAction('Exit')
self.view_menu = self.menu_bar.addMenu("View")
self.view_menu.addAction('set Full Screen')
self.view_menu.addAction('show Status Bar')
self.edit_menu = self.menu_bar.addMenu("Edit")
self.edit_menu.addAction('Cut')
self.edit_menu.addAction('Copy')
self.edit_menu.addAction('Paste')
self.edit_menu.addAction('Find')
self.edit_menu.addAction('Replace')
self.help_menu = self.menu_bar.addMenu("Help")
self.help_menu.addAction('Help')
self.help_menu.addAction('About')
def create_body(self):
form_frame = QFrame()
form_frame.setFrameShape(QFrame.StyledPanel)
form_frame.setMinimumWidth(150)
form_lay = QFormLayout()
f_label = QLabel('Welcome')
s_label = QLabel('Installation')
p_push = QPushButton('Sign in')
p_push.setContentsMargins(10, 20, 10, 10)
self.vbox = QVBoxLayout()
form_lay.addRow(f_label)
form_lay.addRow(s_label)
form_lay.addRow(p_push)
form_frame.setLayout(form_lay)
ver_frame = QFrame()
ver_frame.setFrameShape(QFrame.StyledPanel)
ver_box = QVBoxLayout()
ver_box.setContentsMargins(25, 20, 25, 25)
intro_label = QLabel("Welcome to The Open Space ")
intro_label.setFont(QFont('Serif', 16))
ver_box.addWidget(intro_label)
ver_frame.setLayout(ver_box)
splitter = QSplitter(Qt.Horizontal)
splitter.addWidget(form_frame)
splitter.addWidget(ver_frame)
self.vbox.addWidget(splitter)
self.setCentralWidget(splitter)
def contextMenuEvent(self, event):
men = QMenu()
men.addAction('New')
men.addAction('Open')
quit = men.addAction('Quit')
action = men.exec_(self.mapToGlobal(event.pos()))
if action is quit:
self.close()
def main():
app = QApplication(sys.argv)
win = Window()
app.exec_()
if __name__ == '__main__':
main()
here is a screenshot of my window
Also, how can I add to a top margin on my sign in button, and is there any way I can inherit my context menu's color from my class?