I am using Python 3.3 on Windows 7.
I have a tkinter
application where one Button
fires up a tkinter.simpledialog.Dialog
.
Like this (this is a complete, runnable example):
import tkinter
import tkinter.simpledialog
class Mainframe(tkinter.Frame):
def __init__(self, parent):
super(Mainframe, self).__init__(parent)
self.parent = parent
self.button = tkinter.Button(self, text="Open Dialog")
open_dialog_op = lambda ev: self.open_dialog(ev)
self.button.bind("<Button-1>", open_dialog_op)
self.button.bind("<Return>", open_dialog_op)
self.button.pack(side=tkinter.LEFT)
def open_dialog(self, event):
dialog = tkinter.simpledialog.Dialog(self.parent, "My Dialog")
self.button.config(relief=tkinter.RAISED) # does not help!
root = tkinter.Tk()
Mainframe(root).pack()
root.mainloop()
The behavior:
- if you focus the "Open Dialog"
Button
and type RETURN, all works nicely - if you mouse-click the
Button
, the dialog appears all fine, but - when the dialog closes, the "Open Dialog"
Button
is shown in its depressed (tkinter.SUNKEN
, if I'm not mistaken?) state. - (Interestingly, while the dialog is open, the
Button
is shown normally. The depressed look starts only once the dialog closes.) - I have tried to repair the problem by simply calling
button.config(relief=tkinter.RAISED)
, but that does not appear to do anything at all in this case.
(Actually, my full application starts showing the button as depressed
right after it's clicked, not only once the dialog closes again.
I find this a lot more logical:
The simpledialog
local event loop grabs all events because the simpledialog
is modal; this could include the <ButtonRelease-1>
mouse event at the Button?)
Questions:
- Why does this happen?
- Why might the behavior in my full application differ?
- How can I avoid or repair both?