2011-11-19 80 views
1

我得到一個錯誤:AttributeError的:「按鈕」對象有沒有屬性「設置」 - Tkinter的

self.button.set(str(self)) 
AttributeError: 'Button' object has no attribute 'set' 

我想不出有什麼改變,使其工作。

這裏是代碼的重要組成部分:

class Cell: 
    def show_word(self): 
      """ Shows the word behind the cell """ 
      if self.hidden == True: 
       self.hidden = False 
      else: 
       self.hidden = True 

      self.button.set(str(self)) 

class Memory(Frame): 
    def create_widgets(self): 
     """ Create widgets to display the Memory game """ 
     # instruction text 
     Label(self, 
       text = "- The Memory Game -", 
       font = ("Helvetica", 12, "bold"), 
      ).grid(row = 0, column = 0, columnspan = 7) 

     # buttons to show the words 
     column = 0 
     row = 1 
     the_pairs = self.readShuffle() 
     for index in range(36): 
      temp = Button(self, 
        text = the_pairs[index], 
        width = "7", 
        height = "2", 
        relief = GROOVE, 
        command = lambda x = index: Cell.show_word(the_pairs[x]) 
        ) 
      temp.grid(row = row, column = column, padx = 1, pady = 1) 
      column += 1 
      the_pairs[index].button = temp 
      if column == 6: 
       column = 0 
       row += 1 

回答

4

Button的沒有set屬性。
的Tkinter控件屬性設置與這兩個另類風格:

self.button["text"] = str(self) 

self.button.config(text=str(self)) 

使用其中一個

+0

感謝名單,使得它:d – Amazon

相關問題