Force Focus in Tkinter

Steve Holden steve at holdenweb.com
Wed Dec 7 03:32:10 EST 2005


annagel wrote:
> Thanks for the reply and as it turns out no I don't think I really do
> want to do this.  I started working with tkinter after banging my head
> against the wall for a while with wxwindows so the whole thing ended up
> being a last minute change so I am trying to get most at least of the
> bugs out on a tighter scedule than I planned.  Basically coming from wx
> I had it in my head that I had to call a main loop or nothing would
> work and this meant threads which meant all kinds of extra headaches.
> In my desperation I dropped the whole thing and just started opening
> windows and to my utter suprise it worked.
> 
It may well be that you will need to use threads anyway, I'm afraid - 
ultimately if you want computation to keep on happening while the GUI 
remains responsive then it's almost a requirement. However, it's easier 
to make a start when you are actually seeing windows appear on the 
screen, so I'm glad you are making progress.

> Now I just initialize a root window in my import statement withdraw it
> and let the user use a picture viewer I made with a toplevel window, a
> file chooser, folder chooser, and color chooser.  I am still having a
> couple problems though if anyone out there can shed some light I would
> be apreciative.  First the ColorChooser for some reason this dialog
> does not open on its own.  I am running on Mac and calling it gets my
> python icon bouncing but it does not appear till I go click on the
> icon.  Second I am getting phantom window return with the folder and
> file picker.  If I have used one of these before showing the picture
> viewer and then pop that up when I click on the picture window I also
> get the most recent file dialog (filenameopen or directoryopen) as an
> unresponsive window.
> 
It's probable that you are failing to destroy some widget after use, but 
that's about as much as I can say at present.

> Any advice on either of those problems would be great.  Sorry about the
> intial post in my head I knew doing something like that would just be
> evil, but you start to think crazy when your sollution is too
> complicated for the problem.
> 
As Martin has indicated, more detail in the form of code will be 
necessary to investigate specific problems like that.

In practice the choice between Tkinter and wxPython, PyGtk and the like 
is often either a religious issue or a choice based on the first tool 
that could be manipulated to providing the required results. Ideally you 
want to structure your program so that the GUI can be changed without 
too much effect on the rest of the logic, though that's often easier 
said than done.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list