[PyKDE] Re: GUI wrapper for modules
jbublitz at nwinternet.com
Sun May 30 17:19:00 BST 2004
On Sunday 30 May 2004 06:37, Thorsten Kampe wrote:
> * Phil Thompson (2004-05-30 12:05 +0100)
> > On Sunday 30 May 2004 10:48 am, Thorsten Kampe wrote:
> >> For my first GUI Python application I thought of a wrapper for my
> >> utility modules I have already written. Kind of "EasyGUI" style but
> >> much less sophisticated.
> >> I've got a module "test.py" in $PYTHONPATH containing one function:
> >> def multiply_by_two(x):
> >> return x * 2
> >> Now the GUI app should do the following:
> >> * import module test
> >> * show one button with the following function:
> >> When I click on the button display one input form where I can enter a
> >> number and say "please enter a number". Then the application takes the
> >> number executes test.multiply_by_two(number) and display the result
> >> with message "the result is:"
> >> If anyone could provide me with the appropriate Python/PyQt code (even
> >> some "Pseudo Python code"), I'd be grateful.
> > Have you looked at the tutorial examples that come with PyQt?
> Yes, I've executed them and I've looked at the source code. Same with
> the ones from "BlackAdder" (which seem to be a subset of PyQt's).
> Seems to me like pretty clean code but unfortunately it's not
> commented at all.
> > They are translations to Python of the Qt tutorials - and read the
> > original Qt tutorials in the Qt documentation.
> Hm, the "Qt Tutorial #1 - The 14 Steps" seems interesting although the
> code itself is C (or C++?) and I don't speak C. But I'd still prefer
> some "working code" relating to my own modules, so I could "fiddle"
> and experiment. "Analog clocks" - as beautiful as they are - seem to
> me a bit "academic".
You might want to look at:
GUI Programming with Python: QT Edition
which is available online at:
Basically all PyQt and PyKDE applications follow the same basic "startup"
procedure (even the analog clock, which is where this is copied from):
# create a QApplication instance
a = QApplication(sys.argv)
# create a main widget and set its size
clock = AnalogClock()
# attach the main widget to the app
# show the main widget
# start the application's event loop and wait for user input
The difference is in what you set up as the main widget - it can be a QWidget
or QMainWindow (or even a QButton for a really simple case) to which you add
additional child widgets (in your example a QLineEdit and a QWidget).
However, you'll need to figure out how to create the widgets you need, how to
set up signals and slots to respond to user actions (like clicking a button),
and Boudewijn's book is the best place to start.
More information about the PyQt