Questions about Tk - Newbie

J

Jeppe Jakobsen

------=_Part_4757_13737270.1143840401991
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hey I've just started to learn my first GUI toolkit today. Tk :)

Well, I surfed around for some tutorials for a while but I only found one
that looked good.
Could you link me some good tutorials? I escpecially need some that gives
examples on how a tk and ruby work together.

My biggiest interest in tk right now, is how I store a string given by the
user from an entry in a ruby variable. So if that is not in included in a
tutorial, could someone please give me an example :)

Thanks in advande :)
 
C

Chris Alfeld

# This can be shortened at the expense of clarity.

require 'tk'

root =3D TkRoot.new
v =3D TkVariable.new('Foo')
e =3D TkEntry.new(root,'textvariable'=3D>v)
e.pack
b =3D TkButton.new(root,'text'=3D>'PrintFoo','command'=3D>proc {print v.val=
ue + "\n"})
b.pack

Tk.mainloop
 
J

Jeppe Jakobsen

------=_Part_6510_19557911.1143853440929
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Okay, thanks. I have played a little around with it now, and I can get a
TkText widget to display a variable. Neither through text or insert. How do
you then do it?
 
C

Chris Alfeld

So TkText's don't have textvariable's. They sore their own text
(actually more than just text as it can contain widgets, colors,
different fonts, etc.). Think of TkText and TkCanvas as being
similar. Wheras TkText and TkEntry are not.

require 'tk'

root =3D TkRoot.new
t =3D TkText.new(root)
t.insert('end',"Hi, here is some text!\n")
v =3D t.get('1.0','end')
print v + "\n"
 
J

Jeppe Jakobsen

------=_Part_10953_13138587.1143899937677
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Ok, but what is then common to do when you have a variable pointing to a
string with 1-10 lines of text and you want the string displayed in an
editable field?
 
J

Jeppe Jakobsen

------=_Part_12290_16822680.1143908941279
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

It's for a sort of calculater that I'm writing (It's supposed to make my
math and physics exams less painful ), so I need to be able to edit some
output, shown in the TkText field, before I process the output further.

Thank very much you for the example, I think it was just what I needed to
make it work :)
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top