Hello, here is a complete script that I use in my programs. Surely you should adapt it to your case. It has an extra function called center that serves to center the main window on the screen. I hope to have helped.
from PyQt5 import uic
from PyQt5.QtWidgets import (
QMainWindow,
QApplication,
QDesktopWidget
)
form_2, base_2 = uic.loadUiType('notes.ui')
class MainNotes(base_2, form_2):
def __init__(self, parent=None):
super(base_2, self).__init__(parent)
self.setupUi(self)
class MainApp(QMainWindow):
""" Main Class
"""
def __init__(self):
super(MainApp, self).__init__()
self.mainnotes = MainNotes()
self.ui = uic.loadUi('MainWindow.ui', self)
self.initapp()
def initapp(self):
self.ui.bt_notes.clicked.connect(self.notes)
def notes(self):
"""
Put your code here
"""
self.mainnotes.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def main():
import sys
try:
myapp = QApplication([])
mywindow = MainApp()
mywindow.center()
mywindow.show()
myapp.exec_()
except SystemExit:
sys.exit(0)
if __name__ == '__main__':
main()
Edith your answer instead of adding a new one
– Rafael Tavares