wxpython 文本编辑器状态栏更新
wxpython text editor status bar update
我正在为 Python 2.7 使用 wxpython。我正在使用文本编辑器,但遇到了状态栏问题。
我希望我的状态栏有 Line xx, Column xx
。但是,我只找到了一种在用户输入时使用按键更新它的方法。我还希望用户能够在文本编辑器中四处点击并查看他们的光标位置。我试过了self.control.Bind(wx.EVT_LEFT_DOWN, self.UpdateLineCol)
。我运行这个时候,鼠标左键好像反弹了,所以不能左右点击。
我的UpdateLineCol代码如下:
def UpdateLineCol(self, e):
line = self.control.GetCurrentLine() + 1
col = self.control.GetColumn(self.control.GetCurrentPos())
stat = 'Line %s, Column %s' % (line, col)
self.StatusBar.SetStatusText(stat, 0)
如何绑定鼠标左键来更新状态栏,同时让我用光标四处点击?
您需要调用 event.Skip() 以允许在您的函数之后进行正常处理。
def UpdateLineCol(self, e):
line = self.control.GetCurrentLine() + 1
col = self.control.GetColumn(self.control.GetCurrentPos())
stat = 'Line %s, Column %s' % (line, col)
self.StatusBar.SetStatusText(stat, 0)
e.Skip()
参见:https://wxpython.org/docs/api/wx.MouseEvent-class.html
EVT_LEFT_DOWN Left mouse button down event. The handler of this event should normally call event.Skip() to allow the default processing to take place as otherwise the window under mouse wouldn't get the focus.
编辑:
您的回溯:
File "editor.py", line 211, in <module>
frame = MainWindow(None, 'Avix')
File "editor.py", line 103, in __init__
self.UpdateLineCol(self)
File "editor.py", line 208, in UpdateLineCol
e.Skip()
AttributeError: 'MainWindow' object has no attribute 'Skip'
指定 self.UpdateLineCol(self)
self.UpdateLineCol(self,e)
发生了什么
您在没有将事件作为参数的情况下调用此函数。
我正在为 Python 2.7 使用 wxpython。我正在使用文本编辑器,但遇到了状态栏问题。
我希望我的状态栏有 Line xx, Column xx
。但是,我只找到了一种在用户输入时使用按键更新它的方法。我还希望用户能够在文本编辑器中四处点击并查看他们的光标位置。我试过了self.control.Bind(wx.EVT_LEFT_DOWN, self.UpdateLineCol)
。我运行这个时候,鼠标左键好像反弹了,所以不能左右点击。
我的UpdateLineCol代码如下:
def UpdateLineCol(self, e):
line = self.control.GetCurrentLine() + 1
col = self.control.GetColumn(self.control.GetCurrentPos())
stat = 'Line %s, Column %s' % (line, col)
self.StatusBar.SetStatusText(stat, 0)
如何绑定鼠标左键来更新状态栏,同时让我用光标四处点击?
您需要调用 event.Skip() 以允许在您的函数之后进行正常处理。
def UpdateLineCol(self, e):
line = self.control.GetCurrentLine() + 1
col = self.control.GetColumn(self.control.GetCurrentPos())
stat = 'Line %s, Column %s' % (line, col)
self.StatusBar.SetStatusText(stat, 0)
e.Skip()
参见:https://wxpython.org/docs/api/wx.MouseEvent-class.html
EVT_LEFT_DOWN Left mouse button down event. The handler of this event should normally call event.Skip() to allow the default processing to take place as otherwise the window under mouse wouldn't get the focus.
编辑: 您的回溯:
File "editor.py", line 211, in <module>
frame = MainWindow(None, 'Avix')
File "editor.py", line 103, in __init__
self.UpdateLineCol(self)
File "editor.py", line 208, in UpdateLineCol
e.Skip()
AttributeError: 'MainWindow' object has no attribute 'Skip'
指定 self.UpdateLineCol(self)
self.UpdateLineCol(self,e)
发生了什么
您在没有将事件作为参数的情况下调用此函数。