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?
-
3Could you provide an example of the GUIs you are talking about exactly? – Wesley Bowman Mar 19 '13 at 18:01
-
1Dig into matplotlib... it will generate the graphs and you cand display them where ever. – tdelaney Mar 19 '13 at 18:07
-
Don't have any screenshots handy, but fairly simple GUIs with tabs, tables, and some graphs. – user1507844 Mar 19 '13 at 18:14
3 Answers
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.

- 933
- 2
- 10
- 28
-
The asker wants to know about the ability to create GUI's, not use python in a GUI – Kyle Heuton Mar 19 '13 at 19:19
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:
- http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/
- Embedding a matplotlib figure inside a WxPython panel
- http://www.scipy.org/Cookbook/Matplotlib/EmbeddingInWx
- http://wiki.wxpython.org/MatplotlibFourierDemo
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.

- 1
- 1

- 32,629
- 8
- 45
- 88
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:

- 608
- 3
- 11