【发布时间】:2021-11-08 19:48:55
【问题描述】:
我已经尝试删除pressed() 中的事件参数并移动pressed() 的位置,但没有任何效果......我很卡住。
我尝试过的代码:
import wx
class Window ( wx.Frame ):
def __init__ ( self ):
super().__init__ ( parent = None, title = "Hello World!" )
panel = wx.Panel ( self )
sizer = wx.BoxSizer ( wx.VERTICAL )
self.TextBox = wx.TextCtrl ( panel, pos = ( 5, 5 ), style = wx.TE_MULTILINE | wx.TE_AUTO_URL )
sizer.Add ( self.TextBox, 0, wx.ALL | wx.EXPAND, 5 )
self.button = wx.Button ( panel, label = "Button", pos = ( 5, 40 ) )
self.button.Bind ( wx.EVT_BUTTON, self.pressed )
sizer.Add ( self.button, 0, wx.ALL | wx.CENTER, 5 )
def pressed ( self, event ):
text = self.TextBox.GetValue()
print ( text )
panel.SetSizer ( sizer )
self.Show()
if __name__ == '__main__':
app = wx.App()
window = Window()
app.MainLoop()
错误:
Traceback (most recent call last):
File "E:\Dell\Python\WxPython.py", line 27, in <module>
window = Window()
File "E:\Dell\Python\WxPython.py", line 15, in __init__
self.button.Bind ( wx.EVT_BUTTON, self.pressed )
AttributeError: 'Window' object has no attribute 'pressed'
【问题讨论】: