tk buttons


Read With Formatting | Free Open Source Tutorials Account

Perl Programming
Thread: tk buttons


brunogartner
My intentions are to create a program that does just this, has an exit button and a button that creates a random file but i cant seem to figure out how to put the command to make that file into the button action. Can somebody help me out?

It also gives me this error
Illegal declaration of subroutine main:pen at tk.pl line 14


#Tk program that has exit button and open file button that #creates
#text file when pressed.

use Tk;
use IO::File;
my $mw = MainWindow->new;
$mw->title("File Maker");

$mw->Button(-text => "Exit", -command => sub { exit } )->pack;


$mw->Button(-text => "Open File", -command =>
sub open (FILEHANDLE, "<hello.txt") or die ("Cannot do it");
print <FILEHANDLE>;
close (FILEHANDLE);

MainLoop