I would like to print the content of the txt file opened in a window of the program. Could anybody help me ?

Do you just want to print from the filename itself? Or do you want to open the file in an editor to see it, before you print it? In either case, you probably would use the same code in the callbacks. For MS Windows I would use a Windows only module, but on Linux you can use Net::CUPS::Printer, or use a forked system call to run the lpr command. You could also print directly to the printer, if you wanted more control.

open(LPR, "|lpr -Plp0 >/dev/null 2>&1"); open (FILE,"< $0 ") or die "Couldn't open: $!"; my $text = do {local $/; <FILE>}; close FILE; print LPR $text; close LPR;
or use the module
#!/usr/bin/perl use warnings; use strict; use Net::CUPS::Printer; use Data::Dumper; my @printers = cupsGetPrinters (); print "printers-> @printers\n"; my $printer = cupsGetDefault(); print "Default printer-> $printer\n"; my %options =(); my $jobid = cupsPrintFile($printer,"./$0",'Job1',\%options); print "jobid-> $jobid\n"; my $jobs = cupsGetJobs('lp0',1,0); print "jobs-> $jobs\n"; print Dumper([$jobs]),"\n"; my $cancel = cupsCancelJob('lp0', $jobid); print "cancel-> $cancel\n"; #my $jobs = cupsGetJobs('lp0',1,0); #print "jobs-> $jobs\n"; #print Dumper([$jobs]),"\n"; my $user = cupsUser(); print "user-> $user\n"; exit;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Perl tk - open file and print content by zentara
in thread Perl tk - open file and print content by Giorgio C

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.