[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How can i 'Clear' a TkText...box???

wiz_pendases

10/26/2007 5:52:00 PM

This is what i got ....i need to clear the big text box, when the user
hits the 'clear' button.

<code>

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
</code>

-------------------------------------------------------------------------------------------------------------
plz help....and thanks...

1 Answer

Morton Goldberg

10/27/2007 2:29:00 AM

0

On Oct 26, 2007, at 1:55 PM, wiz_pendases@yahoo.com wrote:

> This is what i got ....i need to clear the big text box, when the user
> hits the 'clear' button.
>
> <code>
>
> 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
> </code>

<code>
require 'tk'

# 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)

# 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')
entry_widget = TkEntry.new(bottom_right_frame) {
background "white"
}.pack('side' => 'left')

# Clear and Exit buttons
TkButton.new(left_frame) do
text "Clear"
command { entry_widget.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

Tk.mainloop
</code>

The change in the order in which the widgets were created is
important. The local entry_widget must exist before in can be used in
the Clear button's command block.

Regards, Morton