Entry Widgets and Buttons
Let's look at a slightly more sophisticated script. Suppose we want to take a pair of phrases and determine whether they are anagrams of each other—that is, whether the letters of one phrase can be rearranged to form the other phrase, ignoring spaces and punctuation.
The algorithm for determining whether two strings are anagrams is quite easy, so we'll leave that aside for now and concentrate on the graphic interface. We obviously need two text entry fields, and for these we'll use TkEntry widgets. Each will be labeled suitably with a TkLabel widget. Finally we'll use a TkVariable to associate a Ruby variable with a text field, although this is more of an implementation detail than a matter of appearance.
You're not ...
Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.