Learn KDE Programming with PyQt

Sebastian Kügler has written a new PyQt tutorial. Python is the perfect language to start learning programming with and this tutorial takes you through making a basic Qt based program. He also shows how pyuic from PyKDE Extensions makes it possible to use Qt Designer with Python. Some wise words to new programmers from the tutorial, "use the examples and try to change things, play around with them, this is the best way to get comfortable".


I like PyQT but there is no well integrated in KDevelop.

You have to transform .ui files from Qt Designer to pyqt , to make this you have to use pyuic to make this pyqt file and then edit in KDevelop.

You edit this file and add python code for buttons for example.

The problem is when you change the ui file , to add other button for example , you have to compile this file to a pyqt file and write back all the buttons code that you make in python.

I think if in KDevelop you can make the .ui file , the code of the buttons in python in other file and then if you press compile / execute file , KDevelop can join all code in one file . If the .ui file change don't change all code and you don't have to write back all python code.

By Yuko at Fri, 2005/12/09 - 6:00am

No! You do not, ever, edit the files generated by pyuic, uic, juic or any other .ui compiler. Include or import the file and subclass the widget you've created, or use it directly, but don't change.ui file by hand.

And if you want an ide specifically tailored to PyQt try Eric3 (or BlackAdder, but that's commercial and not much better than Eric3).

By Boudewijn Rempt at Fri, 2005/12/09 - 6:00am

Just to expland a little bit on what Boudewijn said. You use pyuic to create your class from your .ui, then you create a subclass of that widget. In the subclass you can add all of the extra behavior, methods, event handlers etc that you need. You application should then just use the subclass. The widget class from pyuic can now be regenerated as much as you like without wiping out your handmade code.

As for invoking pyuic by hand, have a look at . This provides extra support for KDE applications. Things like handling installation, i18n, and bunch of other odds and ends. The interesting thing is that it also lets you directly import .ui files into python code without having to manually run pyuic everytime that your .ui file changes. You can just change and save your .ui file in Designer, then start your application up again.


By Simon Edwards at Fri, 2005/12/09 - 6:00am

>>No! You do not, ever, edit the files generated by pyuic, uic, juic or any other .ui compiler. Include or import the file >>and subclass the widget you've created,or use it directly, but don't change.ui file by hand.

How to do this?

By Yuko at Fri, 2005/12/09 - 6:00am

By Boudewijn Rempt at Fri, 2005/12/09 - 6:00am

look at the example "gui coding sucks" in the tutorial.

By Marcio at Fri, 2005/12/09 - 6:00am

For someone like me who has just started to, this is really very much appreciated. I have often marvelled at some of the powers that Qt offers and since I am starting to have another look at Python, this is definitely something that appeals to me and could allow me to make something useful from the skills I learn.

Thanks for this. Kudos. :)


By Pascal Klein at Fri, 2005/12/09 - 6:00am

Gentoo won't install it with anything approaching a modern version of kdelibs installed.

By mikeyd at Fri, 2005/12/09 - 6:00am

Try the PyKDE from kdebindings, I think that one's supposed to work.

I suspect you get a slightly older PyKDE that works with a newer KDE, if that makes any sense ;-)

By Roberto Alsina at Fri, 2005/12/09 - 6:00am

That only seems to include the dcop bindings, not the parts that let you make a full application (with widgets etc.)

By mikeyd at Fri, 2005/12/09 - 6:00am

Look under kdebindings/python

By Richard Dale at Fri, 2005/12/09 - 6:00am

There's no kdebindings package anymore and I was a bit lazy fixing the mess with kdebindings including sip, pyqt and pykde.

By Carlo at Sat, 2005/12/10 - 6:00am


By Pingveno at Tue, 2005/12/13 - 6:00am

I had no real luck with the kdebindings version of PyKDE (at least for KDE 3.4). However, recent PyKDE snapshots do work, although some additional patches may be required. I recommend looking at the Ubuntu source packages (which you can find using the package browser at since some of the necessary patches are included in those archives; look out for python2.4-kde and python2.4-qt along with various sip packages.

By Paul Boddie at Fri, 2005/12/09 - 6:00am

i compiled PyKDE from riverbank:

works fine with KDE 3.4 and 3.5 on gentoo.

By hds at Mon, 2005/12/12 - 6:00am

There's a masked, but not blocked, version at kde-base/pykde.

By Daniel Ross at Sun, 2006/01/22 - 6:00am

LinuxBase has released the first draft of desktop modules

By Tiziano at Fri, 2005/12/09 - 6:00am

Hi Tiziano!

I can assure you that Qt4 will be a part of 3.0.

The LSB Steering Comittee is currently in the process of changing the license criteria to allow for this, and the discussion how to exactly phrase the new criteria has not been finalized yet. For this reason, Qt4 was missing in LSB 3.0 beta. But the stated intention of LSB Desktop workgroup is to include Qt4 alongside, and there are no objections to this.

The final version of LSB 3.0 will be released in January 2006, and by then all of the LSB websites will hopefully be updated and corrected.

Olaf Jan Schmidt, KDE e.V. representative in the LSB workgroups

By Olaf Jan Schmidt at Fri, 2005/12/09 - 6:00am

Good to see that there soon will be a solution for the license criteria problem. Although I still think that Alan Cox's proposal ( would be even better. Just IMHO.

By Christian Loose at Fri, 2005/12/09 - 6:00am

Why not aggregate (or link to) these great tutorials and tools in a location where potential new KDE developers are likely to first look (ie. on the KDE developer website):

By Vlad C. at Fri, 2005/12/09 - 6:00am

Excellent idea. Only problem is how to mantain these link lists (keep them up to date). The other problem is choosing what to put. Sometimes you go to a wiki and get a list of 25 tools to do, say, IM in Linux. But you end up wasting a lot of time, because just two or three of the linked tools are relevant.

What I typically do is google for things. And let the page rank do the job or sorting things out to me. It works, except for very new documents/info ...

By MandrakeUser at Fri, 2005/12/09 - 6:00am

I've added a link to the page.

By Sebastian Kügler at Sat, 2005/12/10 - 6:00am

Great, thanks!

By Vlad C. at Sat, 2005/12/10 - 6:00am

Could someone please provide a complete working example (a hello world) for the KPanelApplet class, I would really like to be able to make my own python-powered panel applets for KDE.

By John Tuymo at Sat, 2005/12/10 - 6:00am

Ummm... For a dog who is too old to be taught new tricks, is PerlQt a dead animal? I think the last ChangeLog for PerlQt is 2-3 years old. Sorry if I raise any hackles by mentioning such a beast in this thread. Candidly - but not caninely :) Paddy Healy

By Long Pa at Sat, 2005/12/10 - 6:00am

I have no clue of it's state but the latest download looks like PerlQt-3.009-b2.tar.gz dated Jul 10, 2005. Not exactly recent, but less than years old:-)

Try the mailinglist for more better information.

By Morty at Sun, 2005/12/11 - 6:00am

How would you go about creating a KDE app that can be controlled simultaneously from the GUI (i.e., the Qt event loop) and an interactive python interpreter? I've seen that IPython allows something similar (see, but there it seems like the main program must be written in Python, or at least started from within a IPython session. Does anyone have any ideas about this?

By ac at Wed, 2005/12/14 - 6:00am

ipython allows you to run existing python code from within the interpreter. it's one of the "magic" functions that come with ipython. this is the usage:


just launch your application, then continue. note you can use the magic funcs for changing directories also. otherwise you need to type the full path, of course. full help/doc is available through the iterpreter.

and yes i know this post is ancient history, but who knows -- it may end up useful.

By jyaan bresy at Sat, 2008/02/09 - 6:00am