TkEntry - input prevention question

M

matt

How do I prevent a keystroke from even updating an entry? My current
solution is:

e.bind_append("KeyRelease") {e.value = e.value.gsub(/\D/, "")}
e.bind_append("Key") {e.value = e.value.gsub(/\D/, "")}

which gives the desired end result, but the character still appears
before being removed...

~Me!
 
H

Hidetoshi NAGAI

Hi,

From: (e-mail address removed) (matt)
Subject: TkEntry - input prevention question
Date: Fri, 30 Apr 2004 12:49:02 +0900
Message-ID: said:
How do I prevent a keystroke from even updating an entry? My current
solution is:
e.bind_append("KeyRelease") {e.value = e.value.gsub(/\D/, "")}
e.bind_append("Key") {e.value = e.value.gsub(/\D/, "")}
which gives the desired end result, but the character still appears
before being removed...

If your Tcl/Tk suppors validatecommand option for entry widgets,
please use the option (see the sample 'entry3.rb' of widget demos
included in the Ruby source archive).
If not, the following script is an example.
-----------------------------------------------------------
require 'tk'

e = TkEntry.new.pack
e.bind('Key', proc{|key| Tk.callback_break if key =~ /\D/}, '%K')

Tk.mainloop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top