Python GUI app to impress the boss?

Eric Brunel eric.brunel at pragmadev.com
Wed Sep 18 04:46:36 EDT 2002


Lee Gray wrote:
[snip]
> For a newbie, what's easier, Tk or wxWindows?

Matter of taste, really... I do prefer Tkinter, because I find it far 
simpler than other GUI toolkits. But then, I've been into Tk for some years 
now, and maybe I'm too used to it.

The first time I've looked at wxWindows and seen what's needed to open a 
simple window, it just made me run away screaming ;-). But seeing it again 
now, it's not that bad. See:

http://www.wxpython.org/tut-part1.php

In fact, example one in this tutorial would be much shorter in Tkinter than 
in wxWindows, but examples 2 & 3 would require much more code in pure 
Tkinter because of the status bar: it's apparently automatically managed by 
wxWindows, but not by Tkinter. Adding Pmw to Tkinter would make things 
easier ( see http://pmw.sourceforge.net ).

For the record, here is the equivalent (untested) Tkinter+Pmw code for 
examples 1 & 3 in the wxPython tutorial:

--- example 1 -------------------------
from Tkinter import *

topWdw = Tk()
topWdw.title("Hello from Tkinter")
topWdw.mainloop()
----------------------------------------

--- example 3 -------------------------
from Tkinter import *
import Pmw

## Main window
topWdw = Tk()
topWdw.title("Hello from Tkinter")
## Status bar
statusBar = Pmw.MessageBar(topWdw)
statusBar.pack(side=BOTTOM, fill=X)
## Helper for menu items
helper = Pmw.Balloon(topWdw)
helper.configure(statuscommand=statusBar.helpmessage)
## Function displaying about screen
def showAbout():
  showinfo('About Me', "This sample program shows off\n"
                       "frames, menus, statusbars, and this\n"
                       "message dialog.")
## Menus
menuBar = Pmw.MainMenuBar(topWdw, balloon=helper)
topWdw.configure(menu=menuBar)
menuBar.addmenu('File', '')
menuBar.addmenuitem('File', 'command',
                    'More information about this program',
                    label='About', command=showAbout)
menuBar.addmenuitem('File', 'separator')
menuBar.addmenuitem('File', 'command',
                    'Terminate the program',
                    label='Exit', command=topWdw.quit)
topWdw.mainloop()
---------------------------------------

Just see for yourself the one you find clearer.

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list