【发布时间】:2016-02-09 00:08:22
【问题描述】:
我想知道如何创建可以单独控制的相同类型按钮的数量(取自用户输入)?我尝试使用类来执行此操作,但它只创建一个按钮。
class GridBtn(QMainWindow):
def __init__(self, self_global, x, y):
super(GridBtn, self).__init__()
self.button = QPushButton("0", self_global)
self.move(x,y)
def change_val(self, val):
self.button = QPushButton(val, self_global)
def returnx(self, x):
return x
def returny(self, y):
return y
即网格生成器引用的 GridBtn 类。
self.grid_x = 3
self.grid_y = 3 #later changed to user input, just for testing
for x in range(self.grid_x):
for y in range(self.grid_y):
for grid_btn in range(self.grid_y):
print("test") #testing if works
#need to fix this to make more efficient
grid_btn = GridBtn(self, x*10, y*10)
self.button_grid_layout.addWidget(grid_btn.button,x,y)
【问题讨论】:
标签: class python-3.x button grid qtgui