From: Mathew Cucuzella on 7 Jun 2010 05:26 I'm writing a Ruby/Tk program where I want a TkEntry field with a state of "readonly" so a user can copy/paste from it, but not modify it. Unfortunately this prevents me from programatically changing it, which I want to do. Is there a better way to accomplish that? Sample code: TkEntry does not display "hi" after button click. <code> require 'tk' top = TkRoot.new entry = TkEntry.new(top) {state "readonly";grid('row'=>0, 'column'=>0)} TkButton.new(top) {text 'Convert'; grid('row'=>1, 'column'=>0); # the "entry" field update fails, as documented command proc {entry.value = "hi"} } Tk.mainloop ## Environment # Ubuntu 10.4 # 2.6.32-22-generic #36-Ubuntu SMP Thu Jun 3 22:02:19 UTC 2010 # i686 GNU/Linux # ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux] # libtcltk-ruby # libtcltk-ruby1.8 </code> Thanks, Mathew Cucuzella -- Posted via http://www.ruby-forum.com/.
From: Hidetoshi NAGAI on 7 Jun 2010 06:23 From: Mathew Cucuzella <kookjr(a)gmail.com> Subject: using TkEntry with copy/paste Date: Mon, 7 Jun 2010 18:26:05 +0900 Message-ID: <1a5a8e5e8201d16e9807a4a633423f5d(a)ruby-forum.com> > I'm writing a Ruby/Tk program where I want a TkEntry field with a > state of "readonly" so a user can copy/paste from it, but not modify > it. Unfortunately this prevents me from programatically changing it, > which I want to do. Is there a better way to accomplish that? How about the following <code> require 'tk' top = TkRoot.new var = TkVariable.new entry = TkEntry.new(top, :state=>'readonly', :textvariable=>var).grid(:row=>0, :column=>0) TkButton.new(top, :text=>'Convert', :command=>proc{var.value = 'hi'}).grid(:row=>1, :column=>0) Tk.mainloop </code> -- Hidetoshi NAGAI (nagai(a)ai.kyutech.ac.jp)
From: Mathew Cucuzella on 7 Jun 2010 12:33 Hidetoshi NAGAI wrote: > How about the following > > <code> > require 'tk' > top = TkRoot.new > var = TkVariable.new > entry = TkEntry.new(top, :state=>'readonly', > :textvariable=>var).grid(:row=>0, :column=>0) > TkButton.new(top, :text=>'Convert', > :command=>proc{var.value = 'hi'}).grid(:row=>1, > :column=>0) > > Tk.mainloop > </code> Thanks, that will work. I tried what I thought was the equivalent (below) but it didn't work. The only real difference was that I didn't pass my config params as function arguments. <code> require 'tk' top = TkRoot.new # variable used in entry field, written with button press text_var = TkVariable.new entry = TkEntry.new(top) {textvariable = text_var; grid('row'=>0, 'column'=>0)} TkButton.new(top) {text 'Convert'; grid('row'=>1, 'column'=>0); command proc { # the next line does not show the string in the TkEntry text_var.value = "using variable" } } </code> -- Posted via http://www.ruby-forum.com/.
From: Hidetoshi NAGAI on 7 Jun 2010 17:16 From: Mathew Cucuzella <kookjr(a)gmail.com> Subject: Re: using TkEntry with copy/paste Date: Tue, 8 Jun 2010 01:33:41 +0900 Message-ID: <384777e0600994c870ed35b566f21dd0(a)ruby-forum.com> > Thanks, that will work. I tried what I thought was the equivalent > (below) but it didn't work. The only real difference was that I > didn't pass my config params as function arguments. (snip) > entry = TkEntry.new(top) {textvariable = text_var; grid('row'=>0, ^^^^^^^^^^^^^^^^^^^^^^^ You define a local variable. Please use "textvariable text_var" or "self.textvariable = text_var". -- Hidetoshi NAGAI (nagai(a)ai.kyutech.ac.jp)
From: Mathew Cucuzella on 7 Jun 2010 23:07 Hidetoshi NAGAI wrote: > You define a local variable. > Please use "textvariable text_var" or "self.textvariable = text_var". Thanks, that fixed it. -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: ActiveSupport getting started / tips / sharings for newcomer Next: invition in textwand |