单击菜单wxpython时如何使状态不消失?

How to make status not disappear when clicking menu wxpython?

我在 Python 中制作了一个带有状态栏和菜单的文本编辑器。单击菜单时,当前状态消失。这是 wxPython 的一部分还是有办法禁用它。如果有办法禁用它,怎么办?

提前致谢

import wx
import wx.stc as stc
import os

class Window(wx.Frame):
    def __init__(self, parent, title):

        wx.Frame.__init__(self, parent, title=title, size=(500, 500))
        self.control = stc.StyledTextCtrl(self, style=wx.TE_MULTILINE | wx.TE_WORDWRAP)

        self.control.Bind(wx.EVT_KEY_UP, self.LineColumn)

        self.FileMenu(), self.MenuBar()
        self.Status_Bar()

    def FileMenu(self):
        self.filemenu = wx.Menu()
        self.new = self.filemenu.Append(wx.ID_ANY, "&New\tCtrl+N")

    def MenuBar(self):
        #MenuBar
        self.menu = wx.MenuBar()
        self.menu.Append(self.filemenu, "&File")
        self.SetMenuBar(self.menu)

    def Status_Bar(self):
        #Status Bar
        self.statusbar = self.CreateStatusBar(1)
        self.LineColumn(self)

    def LineColumn(self, e):
        line = self.control.GetCurrentLine() + 1
        col = self.control.GetColumn(self.control.GetCurrentPos())
        stat = "Ln: %s, Col: %s" % (line, col)
        self.StatusBar.SetStatusText(stat, 0)

    def RandomText(self, e):
        self.StatusBar.SetStatusText("Random Text", 3)

def main():
    app = wx.App()
    frame = Window(None, "Text Editor")
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    main()

点击菜单项默认调用事件 wx.EVT_MENU_HIGHLIGHT
如果你通过了菜单项ahelp text此时会显示在状态区
如果您想绕过此功能,请捕获事件并绕过它。
试试这个:

def FileMenu(self):
    self.filemenu = wx.Menu()
    self.new = self.filemenu.Append(wx.ID_ANY, "&New\tCtrl+N", "Open new file")
    self.Bind(wx.EVT_MENU_HIGHLIGHT, self.Bypass)

def Bypass(self,event):
    pass