Hello,
I am currently learning python by trying to create a GUI with PyQt5, and i'm not very good at it. So i went started going through tutorials at
PyQt5 tutorial - learn GUI programming with PyQt5[
^] and started combining the some of the sections of code to understand it more.
Then i got to then i got to the layout management section encountered a problem of not being able to use QGridLayout and QStatusBar at the same time. I saw somewhere that this can be solved with setCentralWidget() but I couldn't figure out how to use it and couldn't find anything online.
What I have tried:
here is what i have so far. The idea is to get the program to tell you what button you pressed in the status bar.
import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication, QGridLayout
class Problem(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
grid = QGridLayout()
grid.setSpacing(10)
names = [['Cls', 'Bck', '', 'Close'],
['7', '8', '9', '/'],
['4', '5', '6', '*'],
['1', '2', '3', '-'],
['0', '.', '=', '+']]
row_num = 0
column_num = 0
for row in names :
row_num += 1
column_num = 0
for column in row:
column_num += 1
button = QPushButton(column)
grid.addWidget(button, row_num,column_num)
self.setLayout(grid)
self.setGeometry(300,300,290,150)
self.setWindowTitle("not working")
self.show()
if __name__ == '__ma<pre>
in__':
app = QApplication(sys.argv)
ex = Problem()
sys.exit(app.exec_())
The code as it is should produce a window with a calculator like layout. Take out the comments and i get the error
"Problem" has no attribute "statusBar"
I heard that i could use setCentralWidget() but i'm not sure how it works. Couldn't find much about it.