0

I'm really trying to fall in love with Python and move away from Matlab. Is it possible to make Matlab style GUIs in Python? How easy is it by comparison? (I make matlab GUIs programmatically, wouldn't dare use GUIDE) Can I put matplotlib graphics in these GUIs? Is tk or wx (or something else) better for this?

user1507844
  • 5,973
  • 10
  • 38
  • 55

3 Answers3

1

Haven't used Matlab before, not sure about it's GUI. But if you tend to use Python interactively, you may want to give iPython a try. Ipython with Qt can render you an elegant GUI.

Chong
  • 933
  • 2
  • 10
  • 28
1

wxPython has tabs, grids or ListCtrls (i.e. tables) and supports matplotlib and PyPlot for graphs. You can read about using matplotlib at the following links:

To see all the widgets that are included with wxPython, go to www.wxpython.org and click the download link on the left. You'll find that they have a standalone Docs & Demo package that can show you almost every widget and how it works.

Community
  • 1
  • 1
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
1

For simple interfaces you might want to check out the GUI neutral widgets that matplotlib provides, documented here -- http://matplotlib.org/api/widgets_api.html

Here's a simple example of using these GUI neutral widgets to draw a function with variable parameters that are controlled by three slider widgets:

import functools
import numpy as np
import pylab
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons, MultiCursor


def hillfxn(x, B, K, n):
    xn = float(x**n)
    return (B * xn)/(K**n + xn)


def draw_function(x, y, xlabel="Activator concentration (X)", 
                  ylabel="Promoter activity"):
    fig, ax = plt.subplots(1, 1, sharex=True)
    plt.subplots_adjust(left=0.15, bottom=0.25)
    lines = ax.plot(x, y)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.set_ylim(0,max(y)*1.1)
    return fig, ax, lines

def draw_interactive_controls(n, B, K):
    axcolor = 'lightgoldenrodyellow'
    axK = plt.axes([0.1, 0.01, 0.75, 0.03], axisbg=axcolor)
    axB  = plt.axes([0.1, 0.06, 0.75, 0.03], axisbg=axcolor)
    axN  = plt.axes([0.1, 0.11, 0.75, 0.03], axisbg=axcolor)
    Nslider = Slider(axN, "$n$", 1, 10, valinit=n, valfmt='%1.3f')
    Bslider = Slider(axB, "$\\beta$", 0, 20, valinit=B, valfmt='%1.3f')
    Kslider = Slider(axK, "$K$", 0.01, 20, valinit=K, valfmt='%1.3f')       
    return Nslider, Bslider, Kslider

def update_plot(val, x=None, lines=None, ax=None, 
                Nslider=None, Bslider=None, Kslider=None):
    n = Nslider.val
    B = Bslider.val
    K = Kslider.val
    y = [hillfxn(i, B, K, n) for i in x]  
    lines[0].set_ydata(y)
    ax.set_ylim(0,max(y)*1.1)  
    pylab.draw()


if __name__ == "__main__":
    # initial values
    B, K, n = 5, 5, 1
    x= np.linspace(0,30,250)
    y = [hillfxn(i, B, K, n) for i in x]

    # setup initial graph and control settings
    fig, ax, lines = draw_function(x,y)
    Nslider, Bslider, Kslider = draw_interactive_controls(n, B, K)

    # specify updating function for interactive controls
    updatefxn = functools.partial(update_plot, x=x, lines=lines, ax=ax, 
                    Nslider=Nslider, Bslider=Bslider, Kslider=Kslider)

    Nslider.on_changed(updatefxn)
    Bslider.on_changed(updatefxn)
    Kslider.on_changed(updatefxn)
    pylab.show()

This will produce an interface like the following:

matplotlib GUI neutral widgets

Paul M.
  • 608
  • 3
  • 11