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


Groups > comp.lang.python > #10245

Re: Validating Entry in tkinter

From Peter Otten <__peter__@web.de>
Subject Re: Validating Entry in tkinter
Date 2011-07-25 09:32 +0200
Organization None
References <0417c151-9cfa-42b7-8476-17c732f91396@glegroupsg2000goo.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1446.1311579180.1164.python-list@python.org> (permalink)

Show all headers | 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