How can I get the text in the Perl/Tk Text widget?
I have written a script that gets a file name and insert the file content to a Text widget. Now when I close the script window, I n开发者_运维技巧eed it to write the text onto the Unix screen.
How can I get the Text widget content?
My text widget insertion sorce code is:
open(FILE, $file_name);
foreach my $line (<FILE>) {
$text->insert('end', $line);
}
$text->get('1.0','end-1c');
(It's end-1c
– end less one character – for fairly technical reasons; with just end
you'd get an extra newline appended. A known Tk gotcha.)
精彩评论