Dec-02-2018, 10:55 AM
I have a basic Python3 PyQt5 GUI with a working quit button.
The window and frame resize fine and the button resizes horizontally, but not vertically.
After a few days of reading, searching, and failed attempts, I am here to ask for help.
Below is the code for my basic program.
Constructive criticism and suggestions welcome.
The window and frame resize fine and the button resizes horizontally, but not vertically.
After a few days of reading, searching, and failed attempts, I am here to ask for help.
Below is the code for my basic program.
Constructive criticism and suggestions welcome.
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import pyqtSlot
class App(QMainWindow):
def __init__(self):
super().__init__()
self.resize(300, 200)
self.centerscreen()
self.setWindowTitle('Basic testing ground')
self.table_widget = MyTableWidget(self)
self.setCentralWidget(self.table_widget)
self.show()
def centerscreen(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
class MyTableWidget(QWidget):
def __init__(self, parent):
super(QWidget, self).__init__(parent)
self.layout = QVBoxLayout()
# a quit button
self.quitButton = QPushButton("Quit Now!")
# connect to a pyqtSlot
self.quitButton.clicked.connect(self.quitClick)
# Show button
self.layout.addWidget(self.quitButton)
self.setLayout(self.layout)
@pyqtSlot()
def quitClick(self):
app.quit()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
