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


Groups > comp.lang.python > #10245

Re: Validating Entry in tkinter

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '__name__': 0.09; 'attribute': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'tkinter': 0.09; 'wrote:': 0.15; '"__main__":': 0.16; 'called,': 0.16; 'occur.': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'tcl/tk': 0.16; 'tkinter,': 0.16; 'def': 0.16; 'parameters.': 0.23; 'runs': 0.23; 'ago': 0.25; 'function': 0.26; 'import': 0.29; 'script': 0.29; 'cmd': 0.30; 'from:addr:web.de': 0.30; 'widget': 0.30; 'print': 0.32; 'proposed': 0.32; 'entry': 0.33; "i've": 0.33; 'to:addr:python- list': 0.34; 'header:X-Complaints-To:1': 0.34; "can't": 0.34; 'option.': 0.35; "isn't": 0.35; 'url:python': 0.37; 'some': 0.37; 'passed': 0.37; 'but': 0.37; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'something': 0.38; 'should': 0.39; 'header:Mime-Version:1': 0.39; 'skip:v 20': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:r 20': 0.40; 'give': 0.60; 'validate': 0.67; 'verified': 0.73
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Validating Entry in tkinter
Date Mon, 25 Jul 2011 09:32:49 +0200
Organization None
References <0417c151-9cfa-42b7-8476-17c732f91396@glegroupsg2000goo.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084b8ef.dip.t-dialin.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1446.1311579180.1164.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1311579180 news.xs4all.nl 23957 [2001:888:2000:d::a6]:51573
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10245

Show key headers only | View raw


Saul Spatz wrote:

> In tcl/tk an Entry widget can be set to validate its contents with the
> validate option.  You have to give it a validatecommand (vcmd), which is a
> tcl script that runs when some action triggers validation.  Usually, the
> script would use "percent substitutions" so the script would be something
> like {ValidInt %P} where %P is the value of the widget should the proposed
> change occur.
> 
> Can one do something like this in tkinter?  I've verified that with
> 
> e = Entry(master, validate = 'all', vcmd = validInt)
> 
> the validInt function is called, but it isn't passed any parameters. I
> can't find that e has any attribute corresponding to the %P value above.
> 
> Is it not possible to do this in tkinter, or have I overlooked something?

Some time ago I came up with 

http://mail.python.org/pipermail/python-list/2009-September/1220447.html

import Tkinter as tk

def validate(before, after):
    print before, "-->", after
    return after.isdigit()

if __name__ == "__main__":
    root = tk.Tk()
    name = root.register(validate)
    cmd = 'expr {[%(name)s %(parms)s]}' % dict(name=name, parms="%s %P")
    var = tk.StringVar()
    entry = tk.Entry(root, textvariable=var,
                     validate="all", validatecommand=cmd)
    entry.pack()
    entry.focus_set()
    root.mainloop()

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


Thread

Validating Entry in tkinter Saul Spatz <saul.spatz@gmail.com> - 2011-07-24 17:11 -0700
  Re: Validating Entry in tkinter rantingrick <rantingrick@gmail.com> - 2011-07-24 18:03 -0700
  Re: Validating Entry in tkinter Peter Otten <__peter__@web.de> - 2011-07-25 09:32 +0200
  Re: Validating Entry in tkinter Wolfgang Meiners <WolfgangMeiners01@web.de> - 2011-07-25 10:48 +0200
  Re: Validating Entry in tkinter Giacomo Boffi <giacomo.boffi@polimi.it> - 2011-07-27 11:24 +0200

csiph-web