Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: -tk questions

by GrandFather (Saint)
on Jul 26, 2006 at 09:22 UTC ( [id://563737]=note: print w/replies, xml ) Need Help??


in reply to -tk questions

Use the Text widget for multi-line text editing.

use warnings; use strict; use Tk; my $mw = MainWindow->new (-title => "editor"); my $text = $mw->Scrolled ('Text', -font => 'normal', -wrap => 'word', -scrollbars => 'e',); $text->pack (); $mw->Button (-text => "open file", -command => \&openFile)->pack (); MainLoop (); sub openFile { my @filetypes = ( ['Text', '.txt', 'TEXT'], ['Text', '.txt', 'TEXT'], ); my $currentFile = $text->getOpenFile (-defaultextension => '.txt', -filetypes => \@filetypes); }

Self modifying code is generally frowned on as being somewhat difficult to maintain. A setting file would generally be the best way to store persistent data, but there are lots of ways of generating and maintaining the settings file. One fairly easy way to do it is ti use Storable; and keep all your context stuff in a hash. Then you can:

use Storable; # Load persistent stuff my $persistRef = retrieve ('config') if -e 'config'; # Use stuff my $text = $persistRef->{text} || ''; # ... $persistRef->{text} = $text; # Save stuff store $persistRef, 'config';

Update: added file open dialog code to Tk sample


DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://563737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found