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


Groups > comp.lang.python > #64018

Re: Bind event is giving me a bug.

Path csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
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; 'root': 0.05; "'',": 0.07; 'tkinter': 0.07; 'except:': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'def': 0.12; '"enter': 0.16; '3.3,': 0.16; 'better:': 0.16; 'buggy': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'idea:': 0.16; 'key?': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'side.': 0.16; 'tk()': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'command': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'pointer': 0.24; 'help!': 0.26; 'pass': 0.26; 'header:In-Reply- To:1': 0.27; 'label': 0.30; "i'm": 0.30; 'run': 0.32; 'text': 0.33; 'except': 0.35; 'problem.': 0.35; 'something': 0.35; 'received:84': 0.35; 'but': 0.35; 'i.e.': 0.36; 'doing': 0.36; 'should': 0.36; 'button': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:t 30': 0.61; 'email addr:gmail.com': 0.63; 'header:Reply-To:1': 0.67; 'reply- to:no real name:2**0': 0.71; 'bare': 0.84; 'reply- to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=dYa5gxne c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=5FYZ9MsUIQAA:10 a=RzsdHvS__fIA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=wLDnxlw4gyYA:10 a=pGLkceISAAAA:8 a=VqqMUeY1MpmGk_CBLqcA:9 a=Yy6vZyoq8kmozsuA:21 a=70phikPf6EoWI2L7:21 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10
X-AUTH mrabarnett:2500
Date Wed, 15 Jan 2014 21:10:42 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Bind event is giving me a bug.
References <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com>
In-Reply-To <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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>
Newsgroups comp.lang.python
Message-ID <mailman.5545.1389820248.18130.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389820248 news.xs4all.nl 2832 [2001:888:2000:d::a6]:35010
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64018

Show key headers only | View raw


On 2014-01-15 20:16, eneskristo@gmail.com wrote:
> While working with tkinter in python 3.3, I had the following problem.
> def get_text(event):
>              self.number_of_competitors = entered_text.get()
>              try:
>                  self.number_of_competitors = int(self.number_of_competitors)

A bare except like this is virtually never a good idea:

>              except:
>                  pass
>              if type(self.number_of_competitors) == int:
>                  root.destroy()
>              else:
>                  label.config(text = "Enter the number of competitors. Please enter a number.")

Something like this would be better:

     try:
         self.number_of_competitors = int(entered_text.get())
     except ValueError:
         label.config(text="Enter the number of competitors. Please 
enter a number.")
     else:
         root.destroy()

> root = Tk()
> label = Label(root, text = "Enter the number of competitors.")
> label.pack(side = TOP)
> entered_text = Entry(root)
> entered_text.pack()

This will make it call 'get_text' when the button is clicked:

> Button(root, text = "Submit", command = get_text).pack()

This will make it call 'get_text' when the pointer enters the frame:

> root.bind('<Enter>', get_text)

Did you mean '<Return>', i.e. the Return key?

> 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!
>

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


Thread

Bind event is giving me a bug. eneskristo@gmail.com - 2014-01-15 12:16 -0800
  Re: Bind event is giving me a bug. Peter Otten <__peter__@web.de> - 2014-01-15 21:59 +0100
  Re: Bind event is giving me a bug. MRAB <python@mrabarnett.plus.com> - 2014-01-15 21:10 +0000
  Re: Bind event is giving me a bug. eneskristo@gmail.com - 2014-01-15 13:19 -0800
  Re: Bind event is giving me a bug. Peter Otten <__peter__@web.de> - 2014-01-15 22:25 +0100
  Re: Bind event is giving me a bug. Terry Reedy <tjreedy@udel.edu> - 2014-01-15 20:44 -0500

csiph-web