This is what i got …i need to clear the big text box, when the user
hits the ‘clear’ button.
irb
Start up Tk with Ruby
require ‘tk’
#def delete(first, last)
@text.delete(0, end)
#end
#def initialize
Main Window
root = TkRoot.new {title “Homework #4”}
Frames
left_frame = TkFrame.new(root).pack(‘side’ => ‘left’, ‘padx’ => 10,
‘pady’ => 10)
right_frame = TkFrame.new(root).pack(‘side’ => ‘right’, ‘padx’ => 10,
‘pady’ => 10, ‘fill’ => ‘both’, ‘expand’ => true)
top_right_frame = TkFrame.new(right_frame).pack(‘side’ => ‘top’,
‘fill’ => ‘both’, ‘expand’ => true)
bottom_right_frame = TkFrame.new(right_frame).pack(‘side’ => ‘left’,
‘fill’ => ‘both’, ‘expand’ => true)
Clear and Exit buttons
TkButton.new(left_frame) do
text “Clear”
#command {delete(0, end)}
width 5
background “white”
grid(‘column’ => ‘0’, ‘row’ => ‘0’)
end
TkButton.new(left_frame) do
text “Cancel”
command { exit }
width 5
background “white”
grid(‘column’ => ‘0’, ‘row’ => ‘1’)
end
Text Window
@text = TkVariable.new()
@text = " "
TkText.new(top_right_frame) {
background “white”
width 8
borderwidth 2
}.pack(‘side’ => ‘right’, ‘fill’ => ‘both’, ‘expand’ => true,
‘ipady’ => 20, ‘ipadx’ => 20)
Text entry window
TkLabel.new(bottom_right_frame) { text ‘File:’ }.pack(‘side’ =>
‘left’)
TkEntry.new(bottom_right_frame){
background “white”
}.pack(‘side’ => ‘left’)
Tk.mainloop