How to get started in GUI Programming?

J

Jonathan Gardner

I would argue with your assertion that either TKinter of PyGTK are the
best. There are several other good alternatives, including wxPython and
PyQt, which are very comparable, if not better.

I would strongly suggest starting with PyQt. It's my personal favorite.
I wrote a short tutorial on the Python Wiki.

http://wiki.python.org/moin/JonathanGardnerPyQtTutorial

I find that the Qt API is a lot simpler than the alternatives. Plus, it
has great documentation.
 
R

Rembrant

ok i'm begginer in programing but i found some online books so you'll
probably find in them what you need! Just send me a mail and i'll reply
with the address! hope this can be helpfull...
 
L

Luis M. Gonzalez

Try PythonCard (http://pythoncard.sf.net).
Like VB or Delphi (drag and drop widgets), but much simpler, easy and
fun.
It's based on wxWidgets, and it gives your apps a native look, no
matter your platform (much nicer than Tkinter, which looks uglier and
dated).
 
C

Claudio Grondi

I am trying to learn GUI programming in Python, but have to confess I
am finding it difficult.

I am not an experienced programmer - just someone who from time to
time writes small programs for my use. Over the years I have moved
from GWBASIC to QBASIC to Visual Basic, and now trying to move across
to a Linux platform. Python seems to be the best compromise between
the limitations of command line basic programming and the total
incomprehensibility of C.

Googling around it seems the best GUI is either Tkinter or PyGtk. I
found a book which recommended PyGtk, as it had a graphical design
option, Glade. Coming from a VB background I latched onto that and
bought the book (Beginning Python, Wrox), but it was a disappointment
(or more accurately a complete waste of money) - there was
insufficient detail in the text.

I've found the tutorial and reference manual on the PyGtk web site,
but although I've made some progress, I keep reaching points where I
have insufficient background to understand them. Currently I'm stuck
on dialog boxes (the code seems immensely complex for the equivalent of
MsgBox("Do you really want to do this ",vbYesNo) and I haven't
got it to work properly yet) and loading graphical images in anything
other than their original size, but every new step brings another
struggle

I've seen reference to a Tkinter book - something like 'Python
and Tkinter Programming' but it seems to be out of print and
unavailable.

Can anyone offer any suggestions as to the least painful way forwards?

From what you write I conclude, that it is maybe a very good idea to stay
with Visual Basic and use it to create the appropriate ActiveX components
you need in Python and then register them to use it from Python. This way
you can 'marry' what you have already created in Visual Basic easily with
Python.
From what I currently know, there is no 100% cross-platform solution for GUI
related tasks, because each platform has own specifics which usually are
very interesting for use in own programming and that kills as a consequence
the cross-platform usage.

# For example a Yes/No/Abort dialog box can be achieved using the WSHOM.OCX
available in Windows as follows:

import win32com.client
axWshShell = win32com.client.Dispatch("WScript.Shell") # WSHOM.OCX

axWshShell_Popup_Icon_Critical = 16
axWshShell_Popup_Button_AbortRetryIgnore = 2
axWshShell_Popup_NoAutoclose = 0

intRetVal = axWshShell.Popup(
### Raise a message box:
" The Popup() Text" + "\n" +
"",
axWshShell_Popup_NoAutoclose,
" The Popup() Title:",
axWshShell_Popup_Icon_Critical + axWshShell_Popup_Button_AbortRetryIgnore
)

axWshShell_Popup_Clicked_Abort = 3 # [Abort] button
axWshShell_Popup_Clicked_Retry = 4 # [Retry] button
axWshShell_Popup_Clicked_Ignore = 5 # [Ignore] button

if(intRetVal == axWshShell_Popup_Clicked_Abort):
print 'Abort clicked, return value = %i'%(intRetVal,)

if(intRetVal == axWshShell_Popup_Clicked_Retry):
print 'Retry clicked, return value = %i'%(intRetVal,)

if(intRetVal == axWshShell_Popup_Clicked_Ignore):
print 'Ignore clicked, return value = %i'%(intRetVal,)

Hope this is what are you looking for, isn't it?

Claudio
 
K

Kay Schluehr

I am trying to learn GUI programming in Python, but have to confess I
am finding it difficult.

Don't do it if you can prevent it.

GUI - toolkits are very complex beasts and at least to me a source of
pain far more as a joy. Python cannot help you making them
significantly simpler but on the contrary add just another level of
indirection. Python normally shines when you have to glue libraries
together or programming simply Python scripts for a broad range of
purposes but if the wrapped library publishes a huge interface with
hundreds of classes and thousands of methods and attributes the benfit
of Pythons abstraction converges to zero. Python does not offer a good
toolchain to take up with Swing, WinForms or Qt to name just a few
delivered with IDEs that are very helpfull in developing GUI apps. Not
to talk about documentation...

Conclusion: if you are already familiar with BASIC I would just
continue writing BASIC apps using VisualBasic dotNet, Windows Forms as
the underlying GUI toolktit and VisualStudio as IDE. Forget the
coolness factor of the language. Cool people never care a lot what
other people think. If you finally want to glue assemblys/controls
together in Python this is still possible with IronPython or
Python-dotNet ( which is a CPython binding to the CLR, available at
Zope.org ).
 
P

paron

I think the best route is through the browser. Good cross-platform, has
a reasonable toolkit, and it's familiar for users.

You could look at TurboGears.
 
U

UrsusMaximus

I agree with Paron, using HTML forms and such as a minimal GUI front
end meant to be run in a browser is often a good way to go.

But I just want to mention, again, Stephen Ferg's "Easygui" at
http://www.ferg.org/easygui/index.html which is a very easy way to go
for desktop GUI's. You know, I just had a thought: I wonder if Easygui
could be used on handhelds like Pocket PC's, Zaurus, Palm etc? If it
could just be imported as a module it might be an awfully simple way to
create GUI's for handhelds.


Ron Stephens
http://www.awaretek.com/plf.html
 
P

peter.mosley

A big thank you to all who responded. There are too many to reply
individually, but to summarise ...

Thomas Güttler gave a link to an example program, editMetadata.py
which uses yes no dialogs and scaled images. I've not yet tried to
learn from this, but looking at the code it seems to provide exactly
what I am looking for. It uses the gtkMessageDialog class, which I
hadn't come across (the tutorial doesn't seem to mention it?)

Others recommended wxPython, PyQt and various derivatives. The trouble
is there's too much choice! But my experience is that under Linux
nothing ever works out of the box, and so I am reluctant to invite more
grief by installing fresh packages until I am sure those already
installed are not adequate.

Easygui had some supporters. I had already come across this, and while
I agree it is a delightfully simple tool to use, and ideal for i/o
operations, it is not sufficiently flexible for my needs.

One development is that my local public library has, to my surprise,
managed to locate a copy of 'Python and Tkinter Programming' by J.
Grayson. I've not read it yet, and an initial flick through
doesn't look too promising but maybe I am mistaken.. I acknowledge
that Tkinter is a bit dated, and may not have a native 'look and
feel', but for me this would be outweighed by an accessible textbook.

So currently the choice is between continuing with PyGtk, using the
editMetadata.py code as a model, or Tkinter using Grayson's book.
I'll try both and see which is more successful.

Once again thank you to all who responded.
 
B

Brian Elmegaard

Others recommended wxPython, PyQt and various derivatives. The trouble
is there's too much choice!

Agreed, I tried to find /the answer/ some time ago, and I got to the
same conclusion. In addition it is even more difficult to find the
advantages and disadvantages of the different toolkits.

My main reasons for choosing wxpython (but never really try to do
something useful with it) was the native look-and-feel on different
platforms and the many different examples, and the demo application
pysketch.

Unfortunately, even wxpython supports two or three ways of doing
drawings on a canvas, and not that many examples were available for
this.

In addition pyqt should be great, I read. So i have been waiting for
trolltech to release qt4 and just saw that they have. pyqt is not
updated yet.
One development is that my local public library has, to my surprise,
managed to locate a copy of 'Python and Tkinter Programming' by J.
Grayson. I've not read it yet, and an initial flick through
doesn't look too promising but maybe I am mistaken..

I had the same experience with it. I got more from
http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf.
 
C

Cameron Laird

Don't do it if you can prevent it.

GUI - toolkits are very complex beasts and at least to me a source of
pain far more as a joy. Python cannot help you making them
significantly simpler but on the contrary add just another level of
indirection. Python normally shines when you have to glue libraries
together or programming simply Python scripts for a broad range of
purposes but if the wrapped library publishes a huge interface with
hundreds of classes and thousands of methods and attributes the benfit
of Pythons abstraction converges to zero. Python does not offer a good
toolchain to take up with Swing, WinForms or Qt to name just a few
delivered with IDEs that are very helpfull in developing GUI apps. Not
to talk about documentation...

Conclusion: if you are already familiar with BASIC I would just
continue writing BASIC apps using VisualBasic dotNet, Windows Forms as
the underlying GUI toolktit and VisualStudio as IDE. Forget the
coolness factor of the language. Cool people never care a lot what
other people think. If you finally want to glue assemblys/controls
together in Python this is still possible with IronPython or
Python-dotNet ( which is a CPython binding to the CLR, available at
Zope.org ).

There's something about this that bothers me, Kay.

I like the clarity and precision of your explanation. To
avoid trouble is advice worth emphasizing. I applaud your
emphasis on Python's adeptness at co-operating with other
languages.

I think you've left a few things unsaid, though. Others
have pointed out in this thread that, for example, Web
applications are *great* for many GUI requirements. Also,
although toolkit zealots regularly underestimate the
"activation energy" often required to configure a develop-
ment environment, newcomers deserve to know how easy it can
be to start with Tkinter. While it doesn't make for the
slickest MacOS-style applications, it's pedagogically
pertinent that a Mac comes "out of the box" with the ability
to
import Tkinter
Tkinter.Button(Tkinter.Tk(), text = "Push me").pack()
That sort of brevity can encourage beginners in an important
way.
 
D

D H

Kay said:
Don't do it if you can prevent it.

What kind of helpful advice is that?
Conclusion: if you are already familiar with BASIC I would just
continue writing BASIC apps using VisualBasic dotNet, Windows Forms as
the underlying GUI toolktit and VisualStudio as IDE. Forget the
coolness factor of the language. Cool people never care a lot what
other people think. If you finally want to glue assemblys/controls
together in Python this is still possible with IronPython or
Python-dotNet ( which is a CPython binding to the CLR, available at
Zope.org ).

So you recommend VB.NET on comp.lang.python, and then later publicly
flame me for mentioning boo a year ago, as well as spew FUD about other
languages you don't like. Doesn't the python community already have
enough assholes as it is?
 
T

Tim Peters

[D H]
...
Doesn't the python community already have enough assholes as it is?

The Python Software Foundation may well wish to fund a study on that.
Write a proposal! My wild-ass guess is that, same as most other Open
Source communities, we average about one asshole per member. I'd love
to proven wrong, though.

at-my-age-you-need-all-the-evacuation-routes-you-can-get-ly y'rs - tim
 
H

Heiko Wundram

Tim said:
My wild-ass guess is that, same as most other Open
Source communities, we average [at] about one asshole per member.

Tim, you saved my day. QOTW!

--- Heiko.
 
K

Kay Schluehr

D said:
What kind of helpful advice is that?


So you recommend VB.NET on comp.lang.python, and then later publicly
flame me for mentioning boo a year ago, as well as spew FUD about other
languages you don't like. Doesn't the python community already have
enough assholes as it is?

The tone makes the music Doug. The usual crank is obsessed with a few
random ideas and if he does not get enough attention and respect for
them and his own ideosyncratic work he is running around and breathes
fire. The therapeutical advise is usually quite simple: being a little
patient and social but I admit this is very hard for a bloated and
aggrieved ego.

I do not want to repeat my observations and alienations about some
attitudes within the Ruby community in detail. It may suffice to say
that I'm not a Hippie, that I do not consider any PL as "love" and
agree mostly with Bruce Eckels concluding remarks. Nevertheless I find
this new-age / postmodern crossover quite interesting and I do think
that it has certainly it's place in the programming world - no less
than the scientific attitude of e.g. Haskellians or the power
triumphalism of SUN and MS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top