Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

text window does not scroll to end

24 views
Skip to first unread message

Another One

unread,
Oct 9, 2017, 3:58:41 PM10/9/17
to
I am trying to have a text window to scroll to the end. As I understand
it, looking at some examples (eg. http://wiki.tcl.tk/1455), you need to
define the yscrollcommand in the text window to the scrollbar and let
the scrollbar update the yview. In its simplest form it would be like this

frame .t
text .t.log -width 80 -height 7 -borderwidth 2 -relief raised \
-setgrid true -yscrollcommand {.t.scroll set}
scrollbar .t.scroll -command {.t.log yview}
pack .t.scroll -side right -fill y
pack .t.log -side left -fill both -expand true
pack .t -side top -fill both -expand true

However, when I then add messages to the text window with

for {set i 0} {$i<20} {incr i} {
.t.log insert end "text line $i\n"
}

the scrollbar still stays on top. Even when I tell the text window to
update the view with

.t.log yview moveto 1

It still stays with the first lines visible. What have I missed?

Francois Vogel

unread,
Oct 9, 2017, 4:07:23 PM10/9/17
to
Another One a écrit le 09/10/2017 à 21:58 :
> .t.log yview moveto 1
>
> It still stays with the first lines visible.

This works for me on Win...

F.

Rich

unread,
Oct 9, 2017, 4:25:23 PM10/9/17
to
Another One <unk...@domain.invalid> wrote:
> I am trying to have a text window to scroll to the end. ...

> It still stays with the first lines visible. What have I missed?

The "see" subcommand to the text widget:

pathName see index
Adjusts the view in the window so that the character given by
index is completely visible. If index is already visible then
the command does nothing. If index is a short distance out of
view, the command adjusts the view just enough to make index
visible at the edge of the window. If index is far out of view,
then the command centers index in the window.

After you insert text, run a "see end" command, and the last line will
pop into view. No need for a scroll bar at all (although if you want a
user to have a scrollbar, then adding one is good).

Robert Heller

unread,
Oct 9, 2017, 4:27:39 PM10/9/17
to
Works fine with CentOS 6 (Tcl/Tk 8.5.7).

Although, instead of ".t.log yview moveto 1", you should use ".t.log see end".
Directly access the yview command is not recomended.

What O/S are you working under? What version of Tcl/Tk are you using?

>
>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Another One

unread,
Oct 9, 2017, 4:57:39 PM10/9/17
to
Robert Heller wrote:
> At Mon, 9 Oct 2017 21:58:38 +0200 Another One <unk...@domain.invalid> wrote:
>
>>
>> I am trying to have a text window to scroll to the end. As I understand
>> it, looking at some examples (eg. http://wiki.tcl.tk/1455), you need to
>> define the yscrollcommand in the text window to the scrollbar and let
>> the scrollbar update the yview. In its simplest form it would be like this
>>
>> frame .t
>> text .t.log -width 80 -height 7 -borderwidth 2 -relief raised \
>> -setgrid true -yscrollcommand {.t.scroll set}
>> scrollbar .t.scroll -command {.t.log yview}
>> pack .t.scroll -side right -fill y
>> pack .t.log -side left -fill both -expand true
>> pack .t -side top -fill both -expand true
>>
>> However, when I then add messages to the text window with
>>
>> for {set i 0} {$i<20} {incr i} {
>> .t.log insert end "text line $i\n"
>> }
>>
>> the scrollbar still stays on top. Even when I tell the text window to
>> update the view with
>>
>> .t.log yview moveto 1
>>
>> It still stays with the first lines visible. What have I missed?
>
> Works fine with CentOS 6 (Tcl/Tk 8.5.7).
>
> Although, instead of ".t.log yview moveto 1", you should use ".t.log see end".
> Directly access the yview command is not recomended.

To Rich as well,..

Adding '.t.log see end' solved the problem. I am curious though that it
seemed to function in some other OS... When I get hands on a Windows I
will try this out.

Thanks for the solution

>
> What O/S are you working under? What version of Tcl/Tk are you using?
>

Slackware 14.1 - 64 bit - tcl 8.6.1


0 new messages