2016-02-09 67 views
0

我想知道如何創建一個可以單獨控制的相同類型按鈕的數量(取自用戶輸入)?我試圖用類來做到這一點,但它只創建一個按鈕。我如何使用QtGui創建一個按鈕模板(python3.x)

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) 

這是試圖創建按鈕的具體金額,但僅僅是創建一個按鈕,像這樣:window

回答

0

是,你調用一個上面一個子功能,你需要的問題XD