Before you can add any widgets, you must have something to add them to. In Tk, this is called the root window. All widgets in the application are inside of and belong to this one root window. The root window also defines some other things, such as the size and title of the window.
To create a new root window, create a new TkRoot object. You'll notice that the new method takes a block as an argument. This is the way arguments are passed to Tk widgets when they're created. Within the block, there are a number of methods available to further describe how the widget looks or acts. In the following example, a new TkRoot object is created and, within the block, the title method is used to give the window a title. Once the TkRoot object is created, the Tk.mainloop method is run. This will run the Tk program and return to the Ruby program when the Tk window is closed.
#!/usr/bin/env ruby
require 'tk'
root = TkRoot.new do
title "Tk / Ruby"
end
Tk.mainloop


