Key Binding Problem
Terry Reedy
tjreedy at udel.edu
Tue Mar 22 23:52:57 EDT 2016
On 3/22/2016 10:46 PM, Wildman via Python-list wrote:
> Platform: Linux
> Python: v.2.7.9
> Tkinter: v.8.6.2
>
> My program has some buttons for file operations, load_image,
> save_image, and quit. I would like to bind a key that will
> execute the procedures for each of the buttons. The binding
> for the quit button was easy...
>
> root.bind("<q>", quit)
> root.bind("<Q>", quit)
>
> That works but it not executing a quit button procedure.
> It is merely executing an internal command. My problem is
> calling an actual button procedure. Over the last several
> hours I have tried many different syntax arrangements and
> I keep getting "object not defined" errors. I also tried
> placing the bind statements into other places in the code.
> I have run out of ideas.
>
> Below is a basic skeleton of my code. Any help appreciated.
>
> #!/usr/bin/env python
>
> try:
> import Tkinter as tk
> from Tkinter import Tk
The second import is not needed. tk.Tk is short and should be called
just once.
> except ImportError:
> import tkinter as tk
> from tkinter import Tk
ditto.
> import tkFileDialog, tkMessageBox
These are 2.x only and should be after the Tkinter import.
For 3.x, import tk.filedialog, tk.messagebox
--
Terry Jan Reedy
More information about the Python-list
mailing list