Python GUI toolkit

Chris Mellon arkanes at gmail.com
Mon Feb 4 12:45:43 EST 2008


On Feb 4, 2008 10:46 AM, Kevin Walzer <kw at codebykevin.com> wrote:
> 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."
>

Of course it doesn't, because you can implement it yourself. Which is
what you do. Tile itself is inherently unable to provide this because
it's a theming mechanism.

> 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.
>

I know how toolkits work.

> 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.
>

I'm not sure how you keep referring to things you implement yourself
as something that the toolkit supports. As a brief example, some
features that wxPython provides to aid in native "feel" and not just
look:

Stock button support allows you to have native button location, order
and labelling.
Sizer support allows for differently sized controls to be positioned
with the same layout.
Stock menu IDs (like preferences and "About this application...") will
be labelled and placed correctly.
Accelerators will automatically map between Command and Control.
Standard path support to find appropriate user directories.


All of these are things that you can do yourself, of course. You could
have implemented Tile yourself, too, to get the (mostly) native look.
The point is what the toolkit provides, and Tk+Tile, while it mostly
provides native look, does *not* provide native feel. If you want
native feel, you need to implement it yourself.



More information about the Python-list mailing list