Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
radiobutton

Posted by dee00zee (dee00zee), 17 June 2005
I need a little help here..

I try to make a simple gui using radiobutton.
I want the gui to behave this way, when a user select Yes, only enable her to enter inputs at the entry, if she select No then, the entry will not be able to accept input.

As you can see in my code, I try to config the background when the user select No, but it produce error.

Code:

#!/usr/local/bin/wish

frame .top -borderwidth 5
pack .top -side top -fill x

entry .top.ent -width 30 -relief sunken -background white -textvariable path
radiobutton .top.rad1 -text Yes -variable choice -value Yes  
radiobutton .top.rad2 -text No -variable choice -value No -command {if $choice == No { \
                                               .top.ent config -                                                  background grey
                                                     }\
                                                     }
label .top.lab -text "Macro KO Box" -pady 2

pack .top.ent -side right -padx 10
pack .top.lab -side left
pack .top.rad1 .top.rad2 -side left



Posted by admin (Graham Ellis), 17 June 2005
Tcl is interpretted at runtime, so error messages in the syntax are only shown up when you happen to run the fault piece of code and not at compile time.   I think you have the following errors in the block that

The - sign is part of the option - so you if you want to use the background option (for example) you shouldn't use spaces - in other words, write -background rather than -   background.

The { on the previous line should probably be a } (or is it just a } missing, or a { in the if missing?)

The }\ looks to be excess to requirements and will also cause an error. (It may be correct if you need that  extra } I just mentioned ... sorry ... my coding style would be a bit different:

Code:
radiobutton .top.rad2 -text No -variable choice -value No -command {
        if {$choice == No} {  
                   .top.ent config -background grey
                    }
         }


If you want to disable an entry button
    -state disabled
will actually prevent the user from entering data there. Changing the background colour (as in your sample code) will just make it look inactive but won't stop a determined user.  If you want to re-enable entry later, use
     -state normal



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho