Tk gurus:
I want to have a text widget where I can display a running log from a process. Example code below. This all works fine except if the x-axis scroll bar is at it's maximum right hand position relative to the text widget and more text is printed to the widget the x-axis scrollbar moves to it's most left hand position. I want the scrollbar to stay at it's current postion.
This is my first attempt at using Tk.... I can't figure out how to control this - or if's it's controllable. Maybe there is a better method. All suggestions are most welome.
Thanks!
use strict;
use Tk;
my ($mainwindow, $menubar, $display, $text);
my $counter = 0;
$mainwindow = new MainWindow;
$mainwindow->geometry("800x400");
$display = $mainwindow->Scrolled('Text', -relief=>'sunken',
-borderwidth=>'2',
-height=>'24', -scrollbars=>'se', '-width' => 40, '-wrap'=>'none');
$display->pack(-expand=>'1', -fill=>'both');
$text = $display->Subwidget('text'); # need this because yo
+u
can't tie to $display - main widget
tie *STDOUT, ref $text, $text;
create_gui_main();
$text->repeat(
1000, sub {
goto \&mymain;
},
);
MainLoop;
sub mymain() {
# This would normally be real text
$counter++;
print "this is a very long line we need a scrollbar on the x
axis........ this is a very long line we need a scrollbar on the x
axis........ this is a very long line we need a scrollbar on the x
axis........ well the number is current = " . $counter . " \n";
}
# ------------------------ #
sub quitapp() {
exit;
}
# ------------------------ #
sub create_gui_main {
my $menuitems = [
[Cascade => "~File", -menuitems => [
[Button => "~Quit", -command => \&quitapp],
]
],
];
if ($Tk::VERSION >= 800) {
$menubar = $mainwindow->Menu(-menuitems => $menuitems);
$mainwindow->configure(-menu => $menubar);
} else {
$mainwindow->Menubutton(-text => "Pseudo menubar",
-menuitems => $menuitems)->pack;
}
}
__END__
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.