[issue11387] Tkinter, callback functions
Serhiy Storchaka added the comment: This is not Tkinter bug, this is normal Tk behavior. Here is minimal reproducer on Tcl/Tk : button .b -text Click me bind .b Button-1 {tk_messageBox -message The button is sunken!} pack .b I suppose the button is left sunken because the message box steals a focus. In general binding mouse click event for button is not a good idea, because it makes a button non-usable with keyboard. Use the command option. -- nosy: +serhiy.storchaka resolution: - not a bug ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11387 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11387] Tkinter, callback functions
Changes by Terry J. Reedy tjre...@udel.edu: -- stage: - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11387 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11387] Tkinter, callback functions
Nikolay Fomichev morphsa...@gmail.com added the comment: Here it is... import sys if sys.version_info[0] == 3: import tkinter as tk from tkinter import messagebox from tkinter import filedialog else: import Tkinter as tk import tkMessageBox as messagebox import tkFileDialog as filedialog class App(): def __init__(self): self.root = tk.Tk() self.btnMsg = tk.Button(self.root, text='Click me') self.btnMsg.pack() self.btnMsg.bind('Button-1', self.clickMsg) self.btnFd = tk.Button(self.root, text='Click me too') self.btnFd.pack() self.btnFd.bind('Button-1', self.clickFd) self.btnCommand = tk.Button(self.root, text='And now click me') self.btnCommand.pack() self.btnCommand.config(command=self.clickCommand) self.root.mainloop() def clickMsg(self, event): messagebox.showerror(title='Error!', message='The button is sunken!') def clickFd(self, event): filedialog.askdirectory(title='Choose a directory') def clickCommand(self): messagebox.showinfo(title='Success!', message='The button is raised.') App() -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11387 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11387] Tkinter, callback functions
Guilherme Polo ggp...@gmail.com added the comment: I have a different problem here on Mac, but I can manage to reproduce your issue if I apply the following patch: Index: Lib/tkinter/__init__.py === --- Lib/tkinter/__init__.py (revision 88757) +++ Lib/tkinter/__init__.py (working copy) @@ -920,9 +920,9 @@ self.tk.call('bindtags', self._w, tagList) def _bind(self, what, sequence, func, add, needcleanup=1): Internal function. -if isinstance(func, str): -self.tk.call(what + (sequence, func)) -elif func: +#if isinstance(func, str): +#self.tk.call(what + (sequence, func)) +if func: funcid = self._register(func, self._substitute, needcleanup) cmd = ('%sif {[%s %s] == break} break\n' This should help someone else to produce a patch for this problem you reported. It is interesting that this same patch fixes the problem I have here (I get a SIGSEGV if I click the cancel button side the askdirectory dialog). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11387 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11387] Tkinter, callback functions
Terry J. Reedy tjre...@udel.edu added the comment: In 2.7 or 3.2, winxp, when I enclose your code with from tkinter import tk #or Tkinter ... App() I get a window with a buttom that sinks and raises as I press and release the left button. Please post complete runnable code that exhibits the problem. Do not expect us to replace what you deleted. -- nosy: +gpolo, terry.reedy versions: +Python 3.3 -Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11387 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11387] Tkinter, callback functions
New submission from Nikolay Fomichev morphsa...@gmail.com: A simple code: class App(): def __init__(self): self.root = tk.Tk() self.btn = tk.Button(self.root, text='Click me') self.btn.pack() self.btn.bind('Button-1', self.click) self.root.mainloop() def click(self, event): # Messagebox or filedialog pass When the button is clicked, it calls the function where a filedialog or messagebox is called. After the function is done the button changes - it looks like it's pressed. Its relief is sunken. Something like self.btn.config(relief=tk.RAISED) has no effect - relief is raised, but the button still looks pressed. If no dialogs are called, all is fine. But... if instead of bind I use config option command, it works - the function goes well with dialogs, etc and the button is really raised. I checked this in 2.6.6, 2.7, 3.1.2 and 3.2 on Linux and Win, everywhere is the same tune. -- components: Tkinter messages: 129990 nosy: Nikolay.Fomichev priority: normal severity: normal status: open title: Tkinter, callback functions versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11387 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com