The listing below draws a dot wherever the mouse is clicked on the panel, but it seems to work only if both lines
self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
wx.EVT_LEFT_DOWN(self.panel, self.OnLeftDown)
are included. If one or the other is omitted the dot doesn't appear until the next mouse click (so the locations of the dots don't really correspond to the current mouse-click position). Furthermore, two identical values of the mouse coordinates, x, y, are generated in OnLeftDown. What I am doing wrong?
import wx
class Test(wx.Frame):
def __init__(self,parent,title):
noResize = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX)
super(Test,self).__init__(parent,style= noResize, title=title,size=(800,800))
self.P = [ ]
self.SetBackgroundColour((0,0,200))
self.panel = wx.Panel(self)
self.panel.SetBackgroundColour('#faf0e6')
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.panel,1, wx.EXPAND | wx.ALL, 5)
self.SetSizer(self.vbox)
self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
wx.EVT_LEFT_DOWN(self.panel, self.OnLeftDown)
self.Center()
self.Show()
def OnLeftDown(self, e):
e.Skip()
self.dc = wx.ClientDC(self.panel)
self.dc.SetBrush(wx.Brush('BLUE', wx.SOLID))
x, y = e.GetPosition()
self.dc.DrawCircle(x,y,3)
self.P.append( (x,y))
if __name__ == '__main__':
app = wx.App()
Test(None,title='TEST')
app.MainLoop()