34

I am teaching my daughter Python (and myself to some degree) using the Pi, and we have had a great time so far - but the CLI can only take us so far. I have started looking at other toolkits, specifically wx, Qt and GTK. These all seem to have great bindings for Linux in general, though I am not able to find a lot of info specific to the Raspberry Pi. I am open to other toolkits as well - as long as the python bindings are good.

Does anyone have any experience coding to one of these on the pi? Is there a simple apt-get command I need to run to install the necessary packages? Better yet, is there a toolkit ready to go with the stock Raspbian image?

Note: I am currently using Raspbian without issue, though Arch is tempting due to the hard-float ABI issues with mono.

Goyuix
  • 755
  • 2
  • 7
  • 13

6 Answers6

23

I would recommend Tkinter, it is the standard GUI library for Python, and as a result is already installed. The IDLE IDE (which is included with the Raspbian image) not only supports Tkinter but is itself a Tkinter app. In addition most Python books will include at least a chapter on creating GUI's with Tkinter. If you prefer web resources you will want to check out Pythonware's Tkinter tutorial. Additional information and resources can be found on Python.org's Tkinter page.

Ghanima
  • 15,767
  • 15
  • 60
  • 114
Steve Robillard
  • 34,478
  • 17
  • 103
  • 109
  • For the Tkinter tutorial the link is for the second page- here is the intro if anybody wants it: http://www.pythonware.com/library/tkinter/introduction/whats-tkinter.htm – Anonymous Penguin Mar 09 '13 at 20:21
4

I did a wee bit of time with Tkinter 15 years ago, then a few years later I did something with wx. While I was able to get stuff done, I found them a both a bit tedious. I don't know how much the situation has improved since I last used them -- or how much my own learning would make them seem easier today.

However, in the past few months, I've been exploring PySide, which is a PyQt-compatible framework. Incredibly useful is the Qt Designer, which allows you to drag and drop components (push buttons, dials, sliders, checkboxes, etc.) and save them as an XML file with the extension ".ui". pyside-uic then reads that and produces Python code. There are some GREAT tutorial videos out there.

Bo Milanovich has a 29-video series on Udemy (for $15) which I just completed, but also has several free of cost listed on the Qt site: http://wiki.qt.io/PySide_Video_Tutorials. Bo can be a bit "distracted" in his lessons, going off on tangents, but for 29 lessons averaging 30 minutes each, it was definitely worth $15.

I also recently found "Qt Designer - PyQt with Python GUI Programming tutorial" (https://www.youtube.com/watch?v=Dmo8eZG5I2w). That led me to the presenter's site which offers intros to Qt, Tkinter, and Kivy https://pythonprogramming.net/gui-development-tutorials/. I haven't watched them, but based on the Qt Designer tutorial that I did watch, I'm looking forward to the ones on pythonprogramming.net.

Some of the official PyQt and PySide documentation is a bit lacking. Much of it was converted via some automated process from the original Qt documentation, and bits were lost in translation. So, if the docs at https://pyside.github.io/docs/pyside/ are lacking, see the docs at http://doc.qt.io/ and try to translate what you read to Python. But watch the tutorials first, as they will take you a long way.

I briefly looked at GTK a few years ago. It also has a designer, glade. I considered going down that road again, but for the things I've been interested in, there seemed to be more energy behind Qt. I'm JUST starting to explore Kivy, as it seems to be recommended for touch screen work.

A bit late, but I hope this helps.

Ubuntourist
  • 161
  • 2
2

tkinter is the GUI extension to TCL which was used very early in the Python development cycle. IDLE the Python command shell uses tkinter.

for a GUI you need an xorg-x11 service (a daemon) and a presentation manager. X11 is where the display device drivers live. There names begin with xorg-x11-drv-xxxxx. X11 is an HID (Human Interface Device) controller. Mice, tablets, keyboards, etc also connect to the x11 service.

My presentation manager is Gnome, but there are at least 1/2 dozen of them. I understand the Xfce is one the lighter ones.

For GUI Python development tools I use DrPython (code editing, syntax checking, and debugging). wxGlade is a Python drag and drop GUI development environment quite similar to Visual Basic. Both are wxPython applications and do not require root privileges. They can be downloaded from sourceforge.net

My R-Pi-3b is on order. My granddaughter already has one, which is why the order was placed. I've been programming for over 60 years and in Python for more than a decade. I have developed a number of compilers for custom languages and client/server apps for home automation.

2

I have developed GUI application which runs on raspberry pi 2,3. I used both tkinter and pyQt4.

But Where both tkinter and pyQt4 requires lot more coding for placing your widgets and it takes lot of time for layout arrangements.

In my suggestion use QT4 designer to create your UI.It is very easy because of drag and drop functionality ,later you can generate python script .py from .ui file using pyuic4 command and you can also add images in your Ui using qt4 designer for that you have to make resosurce.rc file which later you have to convert in using pyrcc command.

There are several tutorials available.

0

Take a look at appJar. It does not have the drag and drop features of QT4 Designer talked about above, But you can create a nice GUI in just a few minutes depending on what you are trying to accomplish. The Docs on their web page show many great examples. http://appjar.info/

Chad G
  • 1,043
  • 1
  • 7
  • 14
-2

go for pygtk its the best and rock solid stable yet easy for beginners

ngprnk
  • 1
  • 5
    Some additional details would help improve this answer (what makes it the best compared to other alternatives, how do I install it, what makes it easy). – Steve Robillard Sep 14 '13 at 18:26