[Tutor] tkFileDialog bug on windows

Michael Lange klappnase at freenet.de
Sat Dec 3 23:34:01 CET 2005


On Fri, 2 Dec 2005 16:58:26 -0800
Fred Lionetti <lordvader at gmail.com> wrote:

> Hi everyone,
> 
> I may have found a strange bug with tkFileDialog, and I'm wondering if
> anyone has a workaround for the problem.  It happens when you have a
> button (or any other clickable widget) directly behind the
> askopenfilename dialog box and double click on a file.  The button
> (behind the open file dialog) gets clicked, when it shouldn't.  It
> occurs with the code below (but only under windows).
> 
> ----------------------------------
> from Tkinter import *
> import tkFileDialog
> 
> def cmd():
>     print "button was pressed"
> 
> parent = Tk()
> Button(parent, text = "hello", command = cmd, width=30, height = 10).pack()
> tkFileDialog.askopenfilename(parent=parent, title = "Double click on a
> file with the 'hello' button directly behind")
> 
> parent.mainloop()
> ---------------------------------

Hi Fred,

I don't have a windows box here to try it, so I can just guess.
On my linux box the list in the dialog responds to ButtonRelease events,
but I think on windows tk uses native dialogs, and maybe these respond to ButtonPress events;
if this is the case, it may happen that the ButtonRelease occurs *after* the dialog window
has been destroyed, so the event gets delivered to the button in the parent window.

Regards

Michael



More information about the Tutor mailing list