I believe I have found a bug in wxpython (or wxWidgets). I am using WIndows 11, wxpython 4.2.1 wxWidgets 3.2.2.1, Python 3.11.5. Take this simple program (simplified from Getting Started - wxPyWiki):
import wx
class MainWindow(wx.Frame):
def init(self, parent, title):
wx.Frame.init(self, parent, title=title, size=(400,400))
wx.TextCtrl(self, style=wx.TE_MULTILINE)
filemenu = wx.Menu()
filemenu.Append(wx.ID_EXIT, “E&xit”)
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
self.Show(True)
app = wx.App(False)
frame = MainWindow(None, “Sample editor”)
app.MainLoop()
Hit Alt-F then Esc: the menu does disappear but the TextCtrl does not properly regain the focus: the first charer typed is ignored except there is a bleep.
The only fix I have found that works is:
- TextCtrl traps EVT_MENU_CLOSE
- Save mouse position
- Simulate a click with wx.UIActionSimulator
- Restore mouse position
- If the menu is used to say pop up a dialog, do wx.Yield() before popping it up (otherwise there is a bleep because the dialog sees a click outside itself).
Rob Cliffe