# Ruby TK GUI questions

**URL:** <https://www.ruby-forum.com/t/ruby-tk-gui-questions/49254>\
**Category:** Ruby\
**Created:** [December 1, 2005, 8:25pm UTC](https://www.ruby-forum.com/t/ruby-tk-gui-questions/49254 "2005-12-01T20:25:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![htruax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/0ea827/32.png) [@htruax](https://www.ruby-forum.com/u/htruax)\
**Post date:** [December 1, 2005, 8:25pm UTC](https://www.ruby-forum.com/t/ruby-tk-gui-questions/49254/1 "2005-12-01T20:25:27Z")

</div>

Hello,

I added a subject line to my recent email, not sure if that is required.

Here are the questions again:

I am working on a Ruby TK GUI application and have a couple of  
questions:

1. I setup a Listbox widget, and inserted 4 lines of text into it. The  
user  
clicks on any one of the elements of the list, which always holds the  
four  
possible selections. My question is, how do I get the active list  
element to  
display with the highlighting appearance you would see as if it was  
clicked  
on by the user? Right now, my list appears with no selected item until  
someone clicks on an item - I want the Listbox to be created at startup,  
filled with the selections, and then have the currently active element  
displayed in the same manner it would appear if it was clicked on. I  
know  
how to set one of the four selections to be the active item, but I want  
the  
user to ‘see’ this via the highlighting.

2. Another portion of my project writes some text to a text widget. How  
do I  
set the cursor in the text widget at the first char position after the  
insertion is done? I know how to set the focus to that text widget, but  
the  
cursor is at the end of the inserted text, I want to put the cursor at  
the  
first line, first character position.

Any help would be greatly appreciated,

Thank You,

Harry T.

---

<div class="post-metadata">

**Author:** ![htruax](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/0ea827/32.png) [@htruax](https://www.ruby-forum.com/u/htruax)\
**Post date:** [December 2, 2005, 8:35am UTC](https://www.ruby-forum.com/t/ruby-tk-gui-questions/49254/2 "2005-12-02T08:35:57Z")

</div>

From: “Harry T.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Ruby TK GUI questions  
Date: Fri, 2 Dec 2005 04:24:29 +0900  
Message-ID: [200512011424320.SM00796@htruax](mailto:200512011424320.SM00796@htruax)

> 1. I setup a Listbox widget, and inserted 4 lines of text into it. The user  
> clicks on any one of the elements of the list, which always holds the four  
> possible selections. My question is, how do I get the active list element to  
> display with the highlighting appearance you would see as if it was clicked  
> on by the user?

listbox\_widget.curselection

It returns an array containing the numerical indices of  
the selected elements.

> ```
> Right now, my list appears with no selected item until
> 
> ```
> 
> someone clicks on an item - I want the Listbox to be created at startup,  
> filled with the selections, and then have the currently active element  
> displayed in the same manner it would appear if it was clicked on. I know  
> how to set one of the four selections to be the active item, but I want the  
> user to ‘see’ this via the highlighting.

listbox\_widget.selectmode(‘multiple’)  
listbox\_widget.selection\_clear(0, :end)  
[1,2].each{|idx| listbox\_widget.selection\_set(idx)}

```
or, if want to set all,

```

listbox\_widget.selection\_set(0, :end)

> 1. Another portion of my project writes some text to a text widget. How do I  
> set the cursor in the text widget at the first char position after the  
> insertion is done? I know how to set the focus to that text widget, but the  
> cursor is at the end of the inserted text, I want to put the cursor at the  
> first line, first character position.

text\_widget.mark\_set(‘insert’, ‘1.0’)

```
 or

```

ins = TkTextMarkInsert.new(text\_widget)  
ins.set(‘1.0’)

In some case, the following is usefull.

text\_widget.mark\_gravity(‘insert’, :left)
