From: Jeppe Jakobsen Date: 2006-04-13T22:33:18+09:00 Subject: Re: Q about tk buttons ------=_Part_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 numbe= r between 0-20 and tells the user to guess it by writing the guess in an entr= y and then press the button. require "tk" #methods def guess if (guess.value =3D=3D right_guess.value) status.value =3D "Correct!" else number_of_guess.numeric +=3D 1 status.value =3D "Sorry, no luck" end end #variables right_guess =3D TkVariable.new(rand(21)) number_of_guess =3D TkVariable.new(0) guess =3D TkVariable.new() status =3D TkVariable.new("Entry your guess and press the button") #windows root =3D TkRoot.new(:title=3D>"Number guess") #labels lbl_guess =3D TkLabel.new(:textvariable=3D>number_of_guess).pack(:side=3D>"= top", :pady=3D>10) lbl_status =3D TkLabel.new(:textvariable=3D>status).pack(:side=3D>"bottom", :pady=3D>10) #entries entry =3D TkEntry.new(:textvariable=3D>guess).pack(:side=3D>"top", :pady=3D= >10) #buttons button =3D TkButton.new(:text=3D>"Guess", :command=3D>proc{guess}).pack(:side=3D>"top", :pady=3D>10) root =3D 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 : > > From: "Jeppe Jakobsen" > 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" ------=_Part_20988_15341231.1144935195033--