Hi Folks.
I have a TkDialog that I just want to display and then get the answer from it. I was wondering if it was possible to do this without deriving from the class. Its a simple dialog box with a Yes/No question.
ret = TkDialog.new('title'=>'Confirm Exit',
'message'=>'Are you sure you want to exit?',
'buttons'=>['Yes', 'No'],
'default'=>1,
'bitmap'=>'question')
How do I get the answer? Did the user press Yes or No?
I've tried to find the answer to this by searching all the ruby examples on my machine and using Google. I'm either looking for the wrong thing, looking in the wrong place, whatever I can't work out how to do this.
Hoping someone can help me.
Stephen
···
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
Stephen Kellett wrote:
I have a TkDialog that I just want to display and then get the answer
from it. I was wondering if it was possible to do this without deriving
from the class. Its a simple dialog box with a Yes/No question.
Try the TkMessageBox. See
http://members.at.infoseek.co.jp/shiroikumo/ruby/rubytk/index-en.html
for details.
Solved the problem.
ret.value() will return the index of the button pressed. In the example
above that is:
Yes == 0
No == 1
So the code would be:
If ret.value() == 0 # user pressed Yes
TkRoot.destroy();
end
You can also use ret.name() to get the name of the button pressed.
Stephen
···
In message <udKlHZCeWAKDFwic@objmedia.demon.co.uk>, Stephen Kellett <snail@objmedia.demon.co.uk> writes
ret = TkDialog.new('title'=>'Confirm Exit',
'message'=>'Are you sure you want to exit?',
'buttons'=>['Yes', 'No'],
'default'=>1,
'bitmap'=>'question')
How do I get the answer? Did the user press Yes or No?
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
FYI.
There maybe a bug for dialog.name.
If a dialog does not show up yet, the value will be nil, but calling
name will give you exception.
Example:
dialog = TkDialog2.new(:title=>'Hello', :message=>'Exit?',
:buttons=>['Yes', 'No'], :default=>1)
# TkDialog2 will not showing at initialize time
puts dialog.value # print nil
puts dialog.name # exception...
My suggestion is modify dialog.rb on the line # 202
def name
@buttons[@val]
end
by
def name
@val.nil? ? nil : @buttons[@val]
end
Message-ID: <1126711133.601443.197810@g44g2000cwa.googlegroups.com>
There maybe a bug for dialog.name.
If a dialog does not show up yet, the value will be nil, but calling
name will give you exception.
Thank you for your report. I'll fix it on CVS.
···
From: email55555@gmail.com
Subject: Re: TkDialog question
Date: Thu, 15 Sep 2005 00:21:34 +0900
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)