Question

I am looking to include a Cartesian plane in my python apps GUI. Im am building the GUI using wxPython. I am wondering as to the best approach to take? The plane should be populated with images at varying locations depending on the axis.

Any help in regards to this issue would be greatly appreciated.

Regards, Dan

Was it helpful?

Solution

Whilst the lines aren't in exactly the right position (not sure why). You could bind to a panel and draw directly to it like so,

import wx

class Cartesian(wx.Frame):
    def __init__(self, parent=None, id=-1, title=""):
        wx.Frame.__init__(self, parent, id, title, size=(640, 480))

        self.panel = wx.Panel(self)
        self.panel.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, event):
        dc = wx.PaintDC(event.GetEventObject())
        dc.Clear()
        dc.SetPen(wx.Pen(wx.BLACK))
        dc.DrawLine(320, 0, 320, 480)
        dc.DrawLine(0, 240, 640, 240)

app = wx.App(False)
frame = Cartesian()
frame.Show()
app.MainLoop()

So this code creates the panel to draw on based off the frame and then draws in a black pen with the dc.DrawLine() method, which takes 4 parameters, the first x/y coordinates, and the second x/y coordinates.

Alternatively you can use wx.StaticLine() in a similar fashion as such:

import wx

class Cartesian(wx.Frame):
    def __init__(self, parent=None, id=-1, title=""):
        wx.Frame.__init__(self, parent, id, title, size=(640, 480))

        self.panel = wx.Panel(self)

        wx.StaticLine(self.panel, pos=(320, 0), size=(1, 480), style=wx.LI_VERTICAL)
        wx.StaticLine(self.panel, pos=(0, 240), size=(640, 1), style=wx.LI_HORIZONTAL)

app = wx.App(False)
frame = Cartesian()
frame.Show()
app.MainLoop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top