Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; 'else:': 0.03; 'handler': 0.05; 'root': 0.05; '*not*': 0.07; 'method.': 0.07; 'tkinter': 0.07; 'except:': 0.09; 'function,': 0.09; 'method,': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '"enter': 0.16; '3.3,': 0.16; 'argument.': 0.16; 'bind': 0.16; 'buggy': 0.16; 'condensed': 0.16; 'indent': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'should.': 0.16; 'side.': 0.16; 'tk()': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'do.': 0.18; 'seems': 0.21; 'command': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'skip': 0.24; 'help!': 0.26; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'fixed': 0.29; 'label': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'bad.': 0.31; 'allows': 0.31; 'option': 0.32; 'run': 0.32; 'text': 0.33; 'except': 0.35; 'problem.': 0.35; 'but': 0.35; 'event,': 0.36; 'doing': 0.36; 'entry': 0.36; 'should': 0.36; 'being': 0.38; 'button': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'skip:t 30': 0.61; 'received:173': 0.61; 'email addr:gmail.com': 0.63; 'more': 0.64; 'line,': 0.68; 'acts': 0.74; 'bare': 0.84; 'disappears': 0.84; 'experiment': 0.84; 'internally.': 0.84; 'received:fios.verizon.net': 0.84; 'touched,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Bind event is giving me a bug. Date: Wed, 15 Jan 2014 20:44:32 -0500 References: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389836693 news.xs4all.nl 2899 [2001:888:2000:d::a6]:47120 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64038 On 1/15/2014 3:16 PM, eneskristo@gmail.com wrote: > While working with tkinter in python 3.3, I had the following problem. Please paste working code that people can experiment with. from tkinter import * > def get_text(event): If this were a method, (which the indent of the body suggests it once was) it would have to have a 'self' parameter, and you would have to bind a bound method. > self.number_of_competitors = entered_text.get() Since it is just a function, and has no 'self' parameter, this raises NameError. I condensed the function to try: int(entered_text.get()) root.destroy() except ValueError: label.config(text = "Enter the number of competitors. Please enter a number.") > try: > self.number_of_competitors = int(self.number_of_competitors) > except: Bare excepts are bad. > pass > if type(self.number_of_competitors) == int: > root.destroy() > else: > label.config(text = "Enter the number of competitors. Please enter a number.") > root = Tk() > label = Label(root, text = "Enter the number of competitors.") > label.pack(side = TOP) > entered_text = Entry(root) Since Entry only allows one line, I would have thought that it should take a command=func option invoked by \n. Instead, it seems to swallow newlines. > entered_text.pack() > Button(root, text = "Submit", command = get_text).pack() As near as I can tell, the Button button-press event in *not* bound to get_text but to a fixed event handler that calls get_text *without* an argument. > root.bind('', get_text) This does bind to an event so that it does call with an event arg. I just removed this and the window acts as it should. Since get_event ignores event, event=None should make it work either way. However, when I try that, the window disappears without being touched, as if \n is randomly generated internally. So I would say to skip this until you know more than I do. > root.mainloop() > > This is a buggy part of the code. When I run it, instead of doing what it should do, it responds to all events BUT enter. I'm not sure if this error is on tkinters or my side. Please help! -- Terry Jan Reedy