Python GUI toolkit

Kevin Walzer kw at codebykevin.com
Mon Feb 4 11:46:58 EST 2008


Chris Mellon wrote:

> 
> I didn't say inherently unable, I said the toolkit doesn't provide it.
> Note that you said that you did a lot of work to follow OS X
> conventions and implement behavior. The toolkit doesn't help you with
> any of this. A mac-native toolkit (or one that strives for native
> behavior, like wxPython)  eliminates a lot of this work (although, of
> course, not all).


If the toolkit doesn't provide it, then I think that means "inherently 
unable."

On the Mac, Tk provides a mechanism that allows hooking up arbitrary 
events to arbitrary keyboard. Something like:

  self.bind('<Command-Key-N>', lambda event: 
self.authorizeCommand(self.installPackage))

I have to specify the key-combination--that's all. One line of code. No 
implementing of keyboard bindings in C or at the Tcl/Tk or even 
Python-Tkinter level--it's all already defined by the toolkit.

By contrast, Cocoa/Objective-C has a rather complex system for defining 
keyboard events:

http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/chapter_6_section_1.html#//apple_ref/doc/uid/10000060i-CH7-SW1

PyObjC is a thin wrapper over Objective-C, so you'd have to do the 
equivalent calls in Python to implement custom keyboard behavior.

It is true that Cocoa some convenience methods in Interface Builder, 
i.e. common menu commands don't require any extra code: if you are 
developing a document-based application, "Command-C" is implemented  in 
the menu and in the frameworks as "copy (text, image, whatever) to 
clipboard." But "Command-C" also works identically in the Tk console.

Tk does lack some things. It doesn't support drag-and-drop on the Mac. 
It doesn't hook into some of the newer Mac visual styles. Getting access 
to this would require an extension or patching Tk's core. In those 
events, I emulate the behavior or appeareance, which Tk makes very easy.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com



More information about the Python-list mailing list