Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105517
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Terry Reedy <tjreedy@udel.edu> |
| Newsgroups | comp.lang.python |
| Subject | Re: Key Binding Problem |
| Date | Wed, 23 Mar 2016 02:47:47 -0400 |
| Lines | 60 |
| Message-ID | <mailman.31.1458715678.2244.python-list@python.org> (permalink) |
| References | <o6ydncSeoNfrnm_LnZ2dnUU7-IfNnZ2d@giganews.com> <mailman.27.1458702187.2244.python-list@python.org> <L6KdnXoY773thm_LnZ2dnUU7-QOdnZ2d@giganews.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de EDLIrZhjE/0HiCnGfKokJQ4GjCF9YF6Tcvk1ewlDOTCw== |
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'mrab': 0.05; 'method,': 0.07; 'none):': 0.07; 'callback': 0.09; 'event):': 0.09; 'handlers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'typeerror:': 0.09; 'jan': 0.11; 'exception': 0.13; 'def': 0.13; 'ignore': 0.14; 'wed,': 0.15; 'argument': 0.15; '(other': 0.16; '2016': 0.16; 'bind': 0.16; 'did,': 0.16; 'given)': 0.16; 'passed.': 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; 'tried:': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'load': 0.20; 'skip:" 30': 0.20; 'class,': 0.22; 'keys': 0.22; 'parameter': 0.22; 'tkinter': 0.22; 'pass': 0.22; 'am,': 0.23; 'defined': 0.23; '(or': 0.23; 'ignored.': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; "doesn't": 0.26; '(which': 0.26; 'header:X -Complaints-To:1': 0.26; 'sense': 0.26; 'error': 0.27; 'question': 0.27; 'executing': 0.27; 'function': 0.28; 'this.': 0.28; 'skip:_ 10': 0.32; 'class': 0.33; 'traceback': 0.33; 'file': 0.34; "isn't": 0.35; 'should': 0.36; 'there': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'method': 0.37; 'received:org': 0.37; 'itself': 0.38; "won't": 0.38; 'button': 0.38; 'does': 0.39; 'takes': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'some': 0.40; 'received:96': 0.63; 'mar': 0.65; 'binding': 0.66; 'python-list': 0.66; 'here': 0.66; 'click': 0.76; '__call__': 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 | <L6KdnXoY773thm_LnZ2dnUU7-QOdnZ2d@giganews.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:105517 |
Show key headers only | View raw
On 3/23/2016 12:28 AM, Wildman via Python-list wrote:
> On Wed, 23 Mar 2016 03:02:51 +0000, MRAB wrote:
>
>> On 2016-03-23 02:46, Wildman via Python-list wrote:
>>> My question is how do I coax bind into executing the
>>> button procedures? Or is there a way to generate the
>>> button click event from the binding?
>>>
>> It won't let you bind to a function called "load_image" because there
>> isn't a function called "load_image"!
>>
>> The "Window" class, however, does have a method with that name.
>>
>> Try binding the keys in Window.__init__ or Window.init_window:
>>
>> def init_window(self):
>> ...
>> root.bind("<l>", self.load_image)
>
> Here is what I tried:
>
> class Window(tk.Frame):
>
> def __init__(self, master = None):
> tk.Frame.__init__(self,master)
> self.master = master
> root.bind("l", self.load_image)
>
> I get this error and it doesn't make any sense to me:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
> File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
> return self.func(*args)
> TypeError: load_image() takes exactly 1 argument (2 given)
Event handlers must have one parameter (other than 'self' for methods),
the event, as that is what they will be passed. You defined load_image
like this.
def load_image(self):
# load image file
It should be this
def load_image(self, event):
# load image file
You are free to ignore the event object and some people then name the
parameter '_' (or dummy) to signify that it will be ignored.
def load_image(self, _):
# load image file
You must pass the bound method, as you did, and not the function itself
(which has two parameters).
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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