Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: Key Binding Problem Date: Tue, 22 Mar 2016 23:52:57 -0400 Lines: 46 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de d2sqEbmmfkduw717fUU2WQ6+QXTKt0I6OKcjc+a5Fcsg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'importerror:': 0.05; 'buttons': 0.09; 'command.': 0.09; 'python:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'python': 0.10; 'jan': 0.11; 'syntax': 0.13; '"object': 0.16; 'bind': 0.16; 'platform:': 0.16; 'quit.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:Problem': 0.16; 'wrote:': 0.16; 'try:': 0.18; '2.x': 0.22; 'tkinter': 0.22; 'code.': 0.23; 'needed.': 0.23; 'second': 0.24; 'tried': 0.24; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'linux': 0.26; 'appreciated.': 0.27; 'skip:# 10': 0.27; 'errors.': 0.27; 'executing': 0.27; 'operations,': 0.27; 'actual': 0.28; 'arrangements': 0.29; 'once.': 0.29; 'getting': 0.33; 'run': 0.33; 'problem': 0.33; 'file': 0.34; 'except': 0.34; 'but': 0.36; 'should': 0.36; 'basic': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'button': 0.38; 'several': 0.38; 'to:addr:python.org': 0.40; 'called': 0.40; 'some': 0.40; 'received:96': 0.63; 'different': 0.63; 'places': 0.64; 'hours': 0.65; 'binding': 0.66; 'python-list': 0.66; 'ideas.': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105508 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("", quit) > root.bind("", 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