【问题标题】:How can I create a template for a button with QtGui (python3.x)如何使用 QtGui (python3.x) 为按钮创建模板
【发布时间】: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


    【解决方案1】:

    问题是你调用了一个高于你需要 xd 的子函数

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 2012-05-29
      • 1970-01-01
      • 2018-03-27
      • 2010-12-28
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      • 2012-07-21
      相关资源
      最近更新 更多