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




Ruby Programming
Previous Page Home Next Page

Simple Tk Application

A simple Tk application in Ruby might look something like this:

require 'tk'
root = { title "Ex1" } {
  text  'Hello, World!'
  pack  { padx 15 ; pady 15; side 'left' }

Let's look at the code a little more closely. After loading in the tk extension module, we create a root-level frame using We then make a label widget as a child of the root frame, setting several options for the label. Finally, we pack the root frame and enter the main GUI event loop.

It's a good habit to specify the root explicitly, but you could leave it out---along with the extra options---and boil this down to a three-liner:

require 'tk' { text 'Hello, World!' }

That's all there is to it! Armed with one of the Perl/Tk books we reference at the start of this chapter, you can now produce all the sophisticated GUIs you need. But then again, if you'd like to stick around for some more details, here they come.
Ruby Programming
Previous Page Home Next Page

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