wxPython: Calling an event manually

Old topic, but I think I’ve got this figured out after being confused about it for a long time, so if anyone else comes through here looking for the answer, this might help. To manually post an event, you can use self.GetEventHandler().ProcessEvent(event) (wxWidgets docs here, wxPython docs here) or wx.PostEvent(self.GetEventHandler(), event) (wxWidgets docs, wxPython docs) … Read more

Is it possible to pass arguments into event bindings?

You can always use a lambda or another function to wrap up your method and pass another argument, not WX specific. b = wx.Button(self, 10, “Default Button”, (20, 20)) self.Bind(wx.EVT_BUTTON, lambda event: self.OnClick(event, ‘somevalue’), b) def OnClick(self, event, somearg): self.log.write(“Click! (%d)\n” % event.GetId()) If you’re out to reduce the amount of code to type, you … Read more

Is it possible to pass arguments into event bindings?

You can always use a lambda or another function to wrap up your method and pass another argument, not WX specific. b = wx.Button(self, 10, “Default Button”, (20, 20)) self.Bind(wx.EVT_BUTTON, lambda event: self.OnClick(event, ‘somevalue’), b) def OnClick(self, event, somearg): self.log.write(“Click! (%d)\n” % event.GetId()) If you’re out to reduce the amount of code to type, you … Read more

How can I create a simple message box in Python?

You could use an import and single line code like this: import ctypes # An included library with Python install. ctypes.windll.user32.MessageBoxW(0, “Your text”, “Your title”, 1) Or define a function (Mbox) like so: import ctypes # An included library with Python install. def Mbox(title, text, style): return ctypes.windll.user32.MessageBoxW(0, text, title, style) Mbox(‘Your title’, ‘Your text’, … Read more

Retrieve XY data from matplotlib figure [duplicate]

This works: In [1]: import matplotlib.pyplot as plt In [2]: plt.plot([1,2,3],[4,5,6]) Out[2]: [<matplotlib.lines.Line2D at 0x30b2b10>] In [3]: ax = plt.gca() # get axis handle In [4]: line = ax.lines[0] # get the first line, there might be more In [5]: line.get_xdata() Out[5]: array([1, 2, 3]) In [6]: line.get_ydata() Out[6]: array([4, 5, 6]) In [7]: line.get_xydata() … Read more

Python – No handlers could be found for logger “OpenGL.error”

Looks like OpenGL is trying to report some error on Win2003, however you’ve not configured your system where to output logging info. You can add the following to the beginning of your program and you’ll see details of the error in stderr. import logging logging.basicConfig() Checkout documentation on logging module to get more config info, … Read more