Search code examples
pythonwindow

Python window application


I just have general question. I need to start with project where will be placed some real time graphs, graphics etc. What should I use? I heard about pyqt and tkinter only. It will be large project.


Solution

  • I recommend using wxPython because of wxGlade. wxGlade is a fantastic GUI builder for wxPython. It's not difficult to use and has a lot of documentation and guides. I've never had any problems with Python v3.2+.

    Combine wxPython with PyPlot to create a plethora of graphs. Here is one of many tutorials.

    wxPython with PyPlot

    You also can use matplotlib, another popular graphing/drawing library.

    Example with matplotlib

    from numpy import arange, sin, pi
    import matplotlib
    matplotlib.use('WXAgg')
    
    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
    from matplotlib.backends.backend_wx import NavigationToolbar2Wx
    from matplotlib.figure import Figure
    
    import wx
    
    class CanvasPanel(wx.Panel):
        def __init__(self, parent):
            wx.Panel.__init__(self, parent)
            self.figure = Figure()
            self.axes = self.figure.add_subplot(111)
            self.canvas = FigureCanvas(self, -1, self.figure)
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
            self.SetSizer(self.sizer)
            self.Fit()
    
        def draw(self):
            t = arange(0.0, 3.0, 0.01)
            s = sin(2 * pi * t)
            self.axes.plot(t, s)
    
    
    if __name__ == "__main__":
        app = wx.PySimpleApp()
        fr = wx.Frame(None, title='test')
        panel = CanvasPanel(fr)
        panel.draw()
        fr.Show()
        app.MainLoop()