Skip to content

Instantly share code, notes, and snippets.

@Park-Developer
Last active January 1, 2021 05:21
Show Gist options
  • Save Park-Developer/0db5eb9e0ffa8e75aa405afc5623a3ad to your computer and use it in GitHub Desktop.
Save Park-Developer/0db5eb9e0ffa8e75aa405afc5623a3ad to your computer and use it in GitHub Desktop.
pyqt5 : specific widget size
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
grid = QGridLayout()
self.setLayout(grid)
names = ['Cls', 'Bck', '', 'Close',
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+']
positions = [(i,j) for i in range(5) for j in range(4)]
for position, name in zip(positions, names):
if name == '':
continue
button = QPushButton(name)
row, column = position
if row == 2:
button.setFixedHeight(80)
if column == 1:
button.setFixedWidth(50)
grid.addWidget(button, *position)
self.move(300, 150)
self.setWindowTitle('Calculator')
self.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment