[Tkinter-discuss] Need help on gui focus l

Cam Farnell msa01 at bitflipper.ca
Wed Oct 14 22:07:30 CEST 2009

The code given exhibits the problem on my Ubuntu Linux box. For the sake of clarity I enumerate three windows involved in this code:

- The MAIN window which has a button marked "popup" in it.
- The CHILD windows which has a button marked "filedialog" in it.
- The OPEN window which is the tkFileDialog

On my machine clicking on the "popup" and "filedialog" buttons works ok, but once you select a file and click OPEN, then what is on top and visible is the MAIN window whereas what the original poster wanted was to see the CHILD window. Even worse, if (starting from scratch again) you click the "popup" button, then drag the resulting CHILD window to a slightly new position then click the "filedialog" button, the OPEN window appears *under* the CHILD window which seems less than useful.

Cam Farnell

Michael Lange wrote:

> I cannot reproduce this behavior here (linux), maybe it is a platform
> specific problem ? I tried the follwing which works for me as expected:
> ### CODE ###
> from Tkinter import *
> import tkFileDialog
> root = Tk()
> top = Toplevel()
> top.withdraw()
> top.protocol('WM_DELETE_WINDOW', top.withdraw)
> def filedialog():
>     print tkFileDialog.askopenfilename()
> b0 = Button(top, text='filedialog', command=filedialog)
> b0.pack(padx=100, pady=100)
> def popup():
>     top.deiconify()
>     b0.focus_set()
> b1 = Button(root, text='popup', command=popup)
> b1.pack(padx=100, pady=100)
> root.mainloop()
> ### CODE ###
> In case I just did not understand exactly your problem,
> could you post a short code snippet here that shows
> the problem and tell us which platform you are using, please ?
> Michael

More information about the Tkinter-discuss mailing list