Last active
January 1, 2021 05:21
-
-
Save Park-Developer/0db5eb9e0ffa8e75aa405afc5623a3ad to your computer and use it in GitHub Desktop.
pyqt5 : specific widget size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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