From: Hidetoshi NAGAI Date: 2004-04-30T13:52:41+09:00 Subject: Re: TkEntry - input prevention question Hi, From: mhm26@drexel.edu (matt) Subject: TkEntry - input prevention question Date: Fri, 30 Apr 2004 12:49:02 +0900 Message-ID: <13383d7a.0404291947.58120dd8@posting.google.com> > 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 ----------------------------------------------------------- Tk.callback_break can break callback operations of the event. -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)