Python编写GUI
发布网友
发布时间:2022-04-27 05:34
我来回答
共1个回答
热心网友
时间:2022-04-18 05:41
你在构造函数中少创建了posCtrl对象,所以当事件发生时会提示没有posCtrl对象,源代码应该是这个吧:
1 #!/bin/env python
2 import wx
3 class MyFrame(wx.Frame):
4
5 def __init__(self):
6 wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
7 panel = wx.Panel(self, -1)
8 panel.Bind(wx.EVT_MOTION, self.OnMove)
9 wx.StaticText(panel, -1, "Pos:", pos=(10, 12))
10 self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10))
11
12 def OnMove(self, event):
13 pos = event.GetPosition()
14 self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
15
16 if __name__ == '__main__':
17 app = wx.PySimpleApp()
18 frame = MyFrame()
19 frame.Show(True)
20 app.MainLoop()
参考:http://czug.org/python/wxpythoninaction/ch01.rst