【发布时间】:2014-07-27 00:13:15
【问题描述】:
我试图从列表中删除静态文本,但出现错误:AttributeError: 'tuple' object has no attribute 'Destroy'。我似乎找不到解决方法。我的代码:
import wx
class oranges(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Testing',size=(300,300))
self.frame=wx.Panel(self)
subtract=wx.Button(self.frame,label='-',pos=(80,200),size=(30,30))
self.Bind(wx.EVT_BUTTON,self.sub,subtract)
self.trying=[]
self.something=0
def sub(self,event):
for i in zip(self.trying):
i.Destroy()
self.something += 1
self.trying.append(wx.StaticText(self.frame,-1,str(self.something),pos=(200,200)))
self.trying.append(wx.StaticText(self.frame,-1,str(self.something),pos=(250,200)))
if __name__ =='__main__':
app = wx.PySimpleApp()
window = oranges(parent=None,id=-1)
window.Show()
app.MainLoop()
我真的很困惑为什么 StaticText 在一个元组中。提前非常感谢!期待答案!
【问题讨论】:
-
您是否阅读了您在代码中使用的zip function 的文档?
-
不,我知道现在这行不通。还有什么我可以用的吗?
-
我不确定我是否理解您的最后评论。为什么你认为你需要用其他东西代替 zip() 而不是让 for 循环简单地遍历 self.trying 列表? (此外,在销毁 StaticText 对象后,您希望/需要将它们从 self.trying 列表中删除...)
-
用你自己的话来说,你为什么首先在那里使用
zip?它应该完成什么?
标签: python python-2.7 wxpython tuples