在此程序中,我想像在数字小键盘中一样创建数字小键盘。在此程序中,我使用gridlayout创建了数字键盘,但由于给定的图像没有得到,请问有人可以帮助我如何增加此gridlayot中按钮的大小。 下面是我的代码:
while (iterator.hasNext()) {
String color = fn.apply(iterator.next());
if (!colorSet.add(color)) {
iterator.remove();
}
}
答案 0 :(得分:1)
对不起,我正在使用PyQt5
import sys
#from PyQt4 import QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
grid = QGridLayout()
self.setLayout(grid)
names = [
'7', '8', '9', '-',
'4', '5', '6', '+',
'1', '2', '3', 'enter',
'0', '', '.']
positions = [(i,j) for i in range(4) for j in range(4)]
for position, name in zip(positions, names):
if name == '':
continue
button = QPushButton(name)
button.clicked.connect(self.buttonClicked)
button.setMinimumWidth(50)
button.setMinimumHeight(50)
if button.text() == 'enter':
button.setMinimumHeight(110)
grid.addWidget(button, *position, 2, 1)
elif button.text() == '0':
grid.addWidget(button, *position, 1, 2)
else:
grid.addWidget(button, *position, 1, 1)
def buttonClicked(self):
print(self.sender().text())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
ex.setWindowTitle('Calculator')
ex.setGeometry(300, 150, 250, 250)
sys.exit(app.exec_())