【发布时间】:2015-04-09 09:36:14
【问题描述】:
我正在努力学习 Python 和 wxPython;我正在制作一个简单的窗口,应该在控制台上打印 textctrl 元素的内容。但是,我收到此错误:
AttributeError: 'Frame' object has no attribute 't_username'
这是代码中感兴趣的部分:
import sys, wx
app = wx.App(False)
class Frame(wx.Frame):
def Login(self, e):
tmp = self.t_username.GetValue()
print tmp
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, size=(400, 250))
panel = wx.Panel(self)
m_login = wx.Button(panel, wx.ID_OK, "Login", size=(100, 35), pos=(150,165))
t_username = wx.TextCtrl(panel, -1, pos=(100, 50), size=(150, 30))
m_login.Bind(wx.EVT_BUTTON, self.Login)
frame = Frame("Login Screen")
frame.Show()
app.MainLoop()
我试图将 Frame 类的名称,Bind 行改为
self.Bind(wx.EVT_BUTTON, self.Login, m_login)
并删除自我。从tmp,但它没有工作。 感谢您的帮助。
【问题讨论】:
标签: python python-2.7 wxpython