2013-04-25 266 views
1

我正在爲使用Python的當前項目創建一個新的應用程序。這是我第一次使用它,它一直是一種學習體驗......Python - Tkinter - GUI

我的應用程序中有一個按鈕,它調用Python中的askcolor()函數。一切工作正常,但在此之後,它給了我以下錯誤。

AttributeError: 'str' object has no attribute 'set' 

這是我在我的應用程序有工作順序:

  1. Select Color按鈕,用戶點擊:

    self.bc_bttn=Button(self, text='Select Color', command=lambda: self.callback()) 
    
  2. 的函數調用callback功能和我選擇合適的顏色

    def callback(self): 
        (triple, hexstr) = askcolor() 
        if triple: 
         triple_string = str(triple) 
         triple_string2 = re.findall('[0-9, ]',triple_string); 
         triple_bkgColor = ''.join(triple_string2) 
         print triple_bkgColor 
         self.overlayColorValue.set(triple_bkgColor) 
    
  3. self.overlayColorValue.set(triple_bkgColor)更改文本字段項的值,因此用戶將看到應用程序的正確值

  4. 我按下Save按鈕

    self.overlayColorValue = self.bc_ent.get() 
    body.set('overlay-color', self.overlayColorValue) 
    
  5. 我的更改寫入到XML文件

    tree.write(CONFIG_XML) 
    
  6. 這一次一切正常,但如果我想再次做同樣的事情改變顏色。然後,我有以下錯誤,當我點擊Select Color按鈕

    AttributeError: 'str' object has no attribute 'set' 
    
+1

我試圖修正格式。您應該驗證代碼中的縮進並根據需要進行修復。另外,試着想出一個更具描述性的標題。目前的更像是一個標籤列表,我添加了真正的標籤。按[編輯]改善您的問題。 – 2013-04-25 19:08:14

回答

1

您與self.bc_ent.get()的返回值,這是一個str更換您的self.overlayColorValue屬性。

據推測,在此之前,它是一個標籤,你想叫.set()它來代替:

self.overlayColorValue.set(self.bc_ent.get()) 
body.set('overlay-color', self.overlayColorValue.get())