1. Computing

How Can Shoes Have Buttons?

By

1 of 4

A Basic Button
How Can Shoes Have Buttons?

The button is one of the simplest elements your Shoes applications in Ruby. After all, isn't a button just a simple element anyway? It has text and it does something when you click on it. It's just that simple. The button is one of the most used elements in Shoes applications.

The button method takes a single argument: the text to display in the button. Optionally, the button can also takes a block to define what happens when you click on the button.(Of course, a button that doesn't do anything isn't particularly useful).

The following example creates a button that displays an alert when you click on it. The alert method is a lot like the alert method in Javascript or the MessageBox function on Windows. It will display a popup dialog box with your message and an OK button.

Shoes.app :width => 200, :height => 140 do
  button "Press me" do
    alert "You pressed me"
  end
end
  1. About.com
  2. Computing
  3. Ruby
  4. Graphical User Interfaces
  5. Shoes
  6. How Can Shoes Have Buttons?

©2014 About.com. All rights reserved.