As Daniel says, this is the simplest possible KDE program, nothing more than a window. It doesn't even say hello.
#!/usr/bin/env python import sys from qt import * from kdecore import * from kdeui import * a=KApplication(sys.argv) w=QWidget() a.setMainWidget(w) a.setTopWidget(w) w.resize(200,100) w.show() a.exec_loop()
What can we learn from this? Well, we need to load the sys module, in order to be able to pass the commandline arguments to KApplication. That's something that comes for free with C++.
Since version v0.9 of the Python Bindings for KDE, it is no more sufficient to just import the kde module in order to have access to the complete KDE toolkit.
Importing the whole kde module used to load seven megs of library code, of which four or five megs were shared. This still was an improvement over the twenty-five megs, which had been necessary beforehand.
PyKDE memory usage has become much more frugal than that by splitting the bindings into the following libraries:
Well, then we create an application. An application is not the same as a window, and doesn't show up on the screen.
To achieve that landmark, we make a widget, of the type QWidget, make it the main widget of our application, and put it on top, resize it, show it and call exec_loop.
Now that last line is worthy of our attention. It starts the main loop of the application, the equivalent of (in pseudo-code)
do if event=="quit" then exit loop if event=="doThis" then call doThis loop
The c++ equivalent of the python a.exec_loop() is
It seems we don't return an exit status from the main loop of the gui. And the exec is renamed to exec_loop because of a naming conflict.
This was easy, wasn't it? Why not try it with the string "Hello World!" as the second argument in a=KApplication(sys.argv), like a=KApplication(sys.argv, "Hello World!").
Oh, and be sure to check your ~/.kde/share/config/ directory after running this example!