wxPython:对象没有属性错误
自学 Python 和 wxPython。不确定我在这里做错了什么,可以使用比我聪明得多的人的一些见解...
import wx
from wxPython.wx import *
class myGUI(wx.Frame):
def __init__(self, parent, title):
super(myGUI, self).__init__(parent, title=title,
size=(450, 350))
panel = wx.Panel(self)
sizer = wx.GridBagSizer(5, 5)
# Main Database Text, Entry and Browse Button ------------------------------
label_MainDatabase = wx.StaticText(panel, label="Main Database:")
sizer.Add(label_MainDatabase, pos=(0, 0), flag=wx.LEFT|
wx.ALIGN_CENTER_VERTICAL, border=20)
tc_MainDatabase = wx.TextCtrl(panel)
sizer.Add(tc_MainDatabase, pos=(0, 1), span=(1, 3), flag=wx.TOP|
wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
tc_MainDatabase.Value = "DBG: I am properly initialized."
bt_MainDatabase = wx.Button(panel, label="Browse...")
sizer.Add(bt_MainDatabase, pos=(0, 4), flag=wx.LEFT|wx.RIGHT|
wx.ALIGN_CENTER_VERTICAL, border=0)
bt_MainDatabase.Bind(wx.EVT_BUTTON, self.bt_MainDatabaseClick,
bt_MainDatabase)
# --------------------------------------------------------------------------
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
self.Centre()
self.Show()
def bt_MainDatabaseClick(self, event):
# Create a list of filters
self.tc_MainDatabase.SetValue = "A"
if __name__ == '__main__':
app = wx.App()
myGUI(None, title="myGUI")
app.MainLoop()
当我单击“浏览”按钮时,出现以下错误: AttributeError:“myGUI”对象没有属性“tc_MainDatabase”
我做错了什么?我试图从“浏览”按钮捕获信息,然后更新文本控制字段(tc_MainDatabase)。我尝试过重新排列 def 语句的顺序等。
是的,我总是用双脚跳进去。这是我知道如何学习的唯一方法...:)
谢谢。
-周先生
teaching myself Python and wxPython. Not sure what I am doing wrong here, could use some insight from folks much smarter than myself...
import wx
from wxPython.wx import *
class myGUI(wx.Frame):
def __init__(self, parent, title):
super(myGUI, self).__init__(parent, title=title,
size=(450, 350))
panel = wx.Panel(self)
sizer = wx.GridBagSizer(5, 5)
# Main Database Text, Entry and Browse Button ------------------------------
label_MainDatabase = wx.StaticText(panel, label="Main Database:")
sizer.Add(label_MainDatabase, pos=(0, 0), flag=wx.LEFT|
wx.ALIGN_CENTER_VERTICAL, border=20)
tc_MainDatabase = wx.TextCtrl(panel)
sizer.Add(tc_MainDatabase, pos=(0, 1), span=(1, 3), flag=wx.TOP|
wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
tc_MainDatabase.Value = "DBG: I am properly initialized."
bt_MainDatabase = wx.Button(panel, label="Browse...")
sizer.Add(bt_MainDatabase, pos=(0, 4), flag=wx.LEFT|wx.RIGHT|
wx.ALIGN_CENTER_VERTICAL, border=0)
bt_MainDatabase.Bind(wx.EVT_BUTTON, self.bt_MainDatabaseClick,
bt_MainDatabase)
# --------------------------------------------------------------------------
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
self.Centre()
self.Show()
def bt_MainDatabaseClick(self, event):
# Create a list of filters
self.tc_MainDatabase.SetValue = "A"
if __name__ == '__main__':
app = wx.App()
myGUI(None, title="myGUI")
app.MainLoop()
I get the following error when I click the "Browse" button:
AttributeError: 'myGUI' object has no attribute 'tc_MainDatabase'
What am I doing wrong? I am trying to capture information from the Browse button and then update a text control field (tc_MainDatabase). I've tried rearranging the order of the def statements, etc.
And yes, I always jump in with both feet. It's the only way I know how to learn... :)
Thanks.
-Chow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许是因为你说:
而不是:
Maybe it's because you're saying:
instead of: