Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^6: Perl tk - open file and print content

by Giorgio C (Novice)
on Jan 20, 2012 at 10:58 UTC ( #948936=note: print w/replies, xml ) Need Help??

in reply to Re^5: Perl tk - open file and print content
in thread Perl tk - open file and print content

Thanks you for your reply and herlp. Unfortunately with this script i didn't resolve my problem. Because this print out the code of the script itself. I would like to print in that scrolled txt widget what i choose to open when i push a button. ( "open" that calls the function 'Get_open_file' that show me the dir of my PC, than choosing a txt file it should be printed in that scrolled widgets. I don't know if i have been clear! I hope you understand me....please save me ! It's really important
  • Comment on Re^6: Perl tk - open file and print content

Replies are listed 'Best First'.
Re^7: Perl tk - open file and print content
by zentara (Archbishop) on Jan 21, 2012 at 11:19 UTC
    If you want to print multiple files, it might be best to push all file selections into an array, then send the whole array to the printer, after selections are done. There are many ways to do it.
    #!/usr/bin/perl use Tk; use strict; my $TOP = MainWindow->new; my $button = $TOP->Button(-text=> 'Print It' , -command => sub{ my $file_r = &fileDialog($TOP); print"\n selected this file $file_r\n"; # use whatever method you want to send # $file_r to the printer # like with Net::Cups print " printing now!\n"; # system( "lpr -lp0 -f $file_r"); #untested } )->pack(); MainLoop; sub fileDialog { my( $w ) = @_; my @types =( ["C files", [qw/.c++ .cpp .c/]], ["Log files", [qw/.log/]],, ["Text files", [qw/.txt/]], ["All files", '*'] ); my $file = $w->getOpenFile( -filetypes => \@types ); return($file); }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Pheraps i can't explain my self, i try to post the code so you can see where i wrong:
      #......All the menu items are not showed in the code, only the part of + interest.....: # OPEN FILE + $file->command( -label => 'Open', -accelerator => 'Ctrl-o', -underline => 0, -command => \&open_file); $mw->bind('<Control-o>', [\&open_file]); #SUPPORTED FILES TO OPEN my $types_OPEN = [ ['SFF files', '.sff'], ['All Files', '*'],]; sub open_file {my $open = $mw->getOpenFile(-filetypes => $types_OPEN, -defaultextension => '.sff'); $read_fh = IO::File->new("$open",'r'); read_text($read_fh); } sub read_text { my @lines; @lines = <$read_fh>; my $mw = MainWindow->new(-title=>'Colored Text'); $mw => print @lines; MainLoop }
      ........................................................ Now, the script works fine and the content of any opened file is printed out in the terminal! The problem is that i would like to print the content in a GUI windows (not only in the terminal, i'm using UBUNTU) but here the windows is opened but is blank !! Please don't call me pesky, but can you correct this script so to obtain what i need!!! TNX a lots

        stop using print function

        run  perl -MTk -e " my $te = tkinit->Scrolled( q/TextUndo/ )->pack; $te->Load( q/filename/ ); MainLoop "  

        substitute  q/filename/ with a real filename, and when you paste the contents of the program into your real program, use $open like you have in your program, and thats it

        Run the widget demo, it also shows zentara way of using Tk::Text insert method

        Oh, there is no need , but you could use open/print if you really want,but, it helps to know perl Perl:TK - standard output to text widget

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://948936]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2018-06-18 16:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.