Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Ruby Programming
Previous Page Home Next Page

Getting Widget Data

We can get information back from widgets with callbacks and by binding variables.

Callbacks are very easy to set up. The command option (shown in the TkButton call in the example that follows) takes a Proc object, which will be called when the callback fires. Here we use Kernel::proc to convert the {exit} block to a Proc. {
  text "Ok"
  command proc { p mycheck.value; exit }
  pack('side'=>'left', 'padx'=>10, 'pady'=>10)

We can also bind a Ruby variable to a Tk widget's value using a TkVariable proxy. We show this in the following example. Notice how the TkCheckButton is set up; the documentation says that the variable option takes a var reference as an argument. For this, we create a Tk variable reference using Accessing mycheck.value will return the string ``0'' or ``1'' depending on whether the checkbox is checked. You can use the same mechanism for anything that supports a var reference, such as radio buttons and text fields.

mycheck = {   variable mycheck   pack('padx'=>5, 'pady'=>5, 'side' => 'left') }
Ruby Programming
Previous Page Home Next Page

  Published under the terms of the Open Publication License Design by Interspire