------ art_20988_15341231.1144935195033
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Thanks. I want to write a Ruby/Tk version of my first program ever (at that
time I wrote in Delphi). It's basically a program that takes a random number
between 0-20 and tells the user to guess it by writing the guess in an entry
and then press the button.
require "tk"
#methods
def guess
if (guess.value == right_guess.value)
status.value = "Correct!"
else
number_of_guess.numeric += 1
status.value = "Sorry, no luck"
end
end
#variables
right_guess = TkVariable.new(rand(21))
number_of_guess = TkVariable.new(0)
guess = TkVariable.new()
status = TkVariable.new("Entry your guess and press the button")
#windows
root = TkRoot.new(:title=>"Number guess")
#labels
lbl_guess = TkLabel.new(:textvariable=>number_of_guess).pack(:side=>"top",
:pady=>10)
lbl_status = TkLabel.new(:textvariable=>status).pack(:side=>"bottom",
:pady=>10)
#entries
entry = TkEntry.new(:textvariable=>guess).pack(:side=>"top", :pady=>10)
#buttons
button = TkButton.new(:text=>"Guess",
:command=>proc{guess}).pack(:side=>"top", :pady=>10)
root = Tk.mainloop
I think the only problem with my code now is that my button won't run my
method guess. But I don't know why right now, because it seems to me that
the methods from the Pigbox example in the pickaxe are run this way. I'm
probably missing something.
2006/4/13, Hidetoshi NAGAI <nagai / ai.kyutech.ac.jp>:
>
> From: "Jeppe Jakobsen" <jeppe88 / gmail.com>
> Subject: Re: Q about tk buttons
> Date: Thu, 13 Apr 2006 01:31:03 +0900
> Message-ID: <99b4ad3b0604120930hf71a5f0r69cb9c84632b02d7 / mail.gmail.com>
> > Oh sorry I meant to say that it returns 1. If I click the button 29
> times,
> > the label shows 30, but the value that was puts'ed is still 1.
>
> Because, callbacks are called in the event loop (Tk.mainloop).
> If you need some help and tell me what you want,
> I may be able to help you.
> --
> Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)
>
>
--
"winners never quit, quitters never win"
------ art_20988_15341231.1144935195033--