【发布时间】:2013-04-25 18:57:35
【问题描述】:
我正在使用 Python 为我当前的项目创建一个新应用程序。这是我第一次使用它,这是一次学习体验......
我的应用程序中有一个按钮,它从 Python 调用 askcolor() 函数。第一次一切正常,但之后,它给了我以下错误。
AttributeError: 'str' object has no attribute 'set'
这是我在我的应用程序中工作的顺序:
-
用户点击
Select Color按钮:self.bc_bttn=Button(self, text='Select Color', command=lambda: self.callback()) -
函数调用
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) self.overlayColorValue.set(triple_bkgColor)更改文本字段条目的值,以便用户在应用程序中看到正确的值-
我按下
Save按钮self.overlayColorValue = self.bc_ent.get() body.set('overlay-color', self.overlayColorValue) -
我的更改已写入 xml 文件
tree.write(CONFIG_XML) -
这次一切正常,但如果我想再次做同样的事情来改变颜色。然后我点击
Select Color按钮时出现以下错误AttributeError: 'str' object has no attribute 'set'
【问题讨论】:
-
我尝试修复格式。您应该验证代码中的缩进并在需要时对其进行修复。此外,尝试提出一个更具描述性的标题。当前的更像是一个标签列表,我添加了真正的标签。按edit 改进您的问题。
标签: python user-interface python-2.7 tkinter