You are not logged in.

#1 2009-06-22 17:03:52

luskjh
Member
Registered: 2009-03-24
Posts: 19

Perl (Tk) Help

Hi,

I recently made a script to help my church's not-so-computer-adept webmaster.

I then decided to "gui-fy" it with perl tk, which looks lik this: http://www.pastie.org/520394. (EDIT: link was not working)

#!/usr/bin/perl -w

use Tk;
use strict;

my $mw = MainWindow -> new;
$mw -> geometry( "200x250" );
$mw -> title( "Button Test" );

$mw -> Label( -text => "Date: ") -> pack();
my $date_entry = $mw -> Entry() ->pack();
$mw -> Label( -text => "Sermon Name: ") -> pack();
my $sermon_entry = $mw -> Entry() ->pack();
$mw -> Label( -text => "Pastor: ") -> pack();
my $pastor_entry = $mw -> Entry() ->pack();
$mw -> Label( -text => "mp3 File (with .mp3 attached ): ") -> pack();
my $mp3_entry = $mw -> Entry() ->pack();

my $button1 = $mw->Button(-text => "Ok", -command => \&button1_sub)->pack();



sub button1_sub
{
    my $date = $date_entry->get();
    my $sermon = $sermon_entry->get();
    my $pastor = $pastor_entry->get();
    my $mp3 = $mp3_entry->get();


    my $yesno_button = $mw -> messageBox( -message => "Date: $date\nSermon Name: $sermon\nPastor: $pastor\nmp3: $mp3\nIs this correct?", -type => "yesno" );

    if ( $yesno_button eq "Yes" )
     {
        open TABLE, "table.html" or die "Could not opn file: $!\n";

        my @table = <TABLE>;
        my @first = @table[0..6];
        my @second = @table[7..$#table];
        my @newhtml = ( 
        "<TR>",
        "<TD vAlign=top width=\"10%\"><p class=sermondate>$date</p></td>",
        "<TD vAlign=top width=\"60%\"><p class=sermonseason>$sermon</p></td>",
        "<TD vAlign=top width=\"20%\"><p class=sermonspeaker>$pastor</p></td>",
        "<TD vAlign=top width=\"10%\"><p class=sermonlink><A href=\"$mp3\">Listen</a></p></td>"
        );

        #puts the arrays back together

        push ( @first, @newhtml );
        my @new = ( @first, @second );

        open OUTPUT, ">table.html" or die "Couldn't write to file: $!\n";

        close OUTPUT or die "Error closing file: $!\n";

    }
    
}


MainLoop;

It opens fine:

http://lh5.ggpht.com/_G5Oc_XJPXIE/Sj-28 … shot_1.jpg

Your can enter text fine:

http://lh4.ggpht.com/_G5Oc_XJPXIE/Sj-28 … shot_2.jpg

It even reconizes the text fine:

http://lh6.ggpht.com/_G5Oc_XJPXIE/Sj-28 … enshot.jpg

but then it wipes "table.html" ( http://www.pastie.org/520389 ) sad

Any ideas on this?

All help is greatly appreciated smile

-jhl

Last edited by luskjh (2009-06-22 17:08:12)


Calm down, it is only ones and zeroes.
       -flyingfsck ( on /. )

Offline

#2 2009-06-22 17:23:40

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Perl (Tk) Help

luskjh wrote:
    open OUTPUT, ">table.html" or die "Couldn't write to file: $!\n";

        close OUTPUT or die "Error closing file: $!\n";

but then it wipes "table.html" ( http://www.pastie.org/520389 ) sad

You're not writing the table to the file.
Add this between the two lines above:

print OUTPUT join("\n", @new);

If that doesn't work I'll take another look at it. I only skimmed your code because you use different conventions than I do so I may have missed something.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#3 2009-06-22 18:14:26

luskjh
Member
Registered: 2009-03-24
Posts: 19

Re: Perl (Tk) Help

Oh, Thanks *slaps forehad* I took that out when I copy/pasted the code, for some reason thinking it had to do with th command line version roll tongue.

Anyway, thanks again smile

-jhl


Calm down, it is only ones and zeroes.
       -flyingfsck ( on /. )

Offline

#4 2009-06-22 18:34:37

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Perl (Tk) Help

Forehead-slapping moments are an integral part of programming. smile

If the code works the way that you want it to now, then please edit the original post and add "[SOLVED]" to the beginning of the subject line.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB