Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105508

Re: Key Binding Problem

From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: Key Binding Problem
Date 2016-03-22 23:52 -0400
Message-ID <mailman.28.1458705193.2244.python-list@python.org> (permalink)
References <o6ydncSeoNfrnm_LnZ2dnUU7-IfNnZ2d@giganews.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-22 21:46 -0500
  Re: Key Binding Problem MRAB <python@mrabarnett.plus.com> - 2016-03-23 03:02 +0000
    Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-22 23:28 -0500
      Re: Key Binding Problem Terry Reedy <tjreedy@udel.edu> - 2016-03-23 02:47 -0400
        Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-23 10:40 -0500
        Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-23 10:58 -0500
          Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-23 20:34 -0400
            Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-23 21:17 -0500
              Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-24 08:06 -0400
                Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-24 11:19 -0500
                Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-24 21:43 -0400
                Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-24 23:37 -0500
                Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-25 12:50 -0400
  Re: Key Binding Problem Terry Reedy <tjreedy@udel.edu> - 2016-03-22 23:52 -0400
    Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-22 23:30 -0500

csiph-web