Thread Tk::Error: not a Tk object (2 answers)
Opened by xiconfjs at 2006-10-03 17:13

renee
 2006-10-03 17:54
#45867 #45867
User since
2003-08-04
14371 articles
ModeratorIn
[Homepage] [default_avatar]
Ein typischer Fall von Wiki:use strict hilft. Mit strict und warnings bekommst Du nämlich folgende Meldungen:
Code: (dl )
1
2
3
4
5
Variable "$entry" will not stay shared at C:\community\toplevel.pl line 32.
Variable "$window2" will not stay shared at C:\community\toplevel.pl line 33.
Global symbol "$variable" requires explicit package name at C:\community\toplevel.pl line 22.
Global symbol "$variable" requires explicit package name at C:\community\toplevel.pl line 34.
Execution of C:\community\toplevel.pl aborted due to compilation errors.


Du solltest es besser so schreiben:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl

use strict;
use warnings;
use Tk;
use Tk::HList;
use Tk::ItemStyle;

my $variable;
my $fenster = new MainWindow;
my $hl = $fenster->HList(-width => 50,)->pack();
my $style = $hl->ItemStyle('text',
-foreground => '#FF0000',
-selectforeground => '#FF0000'
);

my $toplevel = $fenster->toplevel;
my $menubar = $toplevel->Menu(-type => 'menubar');
$toplevel->configure(-menu => $menubar);
my $datei = $menubar->cascade(-label => '~Datei',
-tearoff => 0);
$datei->command(-label => 'Zeige', -command => sub{nickchange()});
$datei->command(-label => 'Quit', -command => [$fenster=>'destroy']);

$hl->repeat(1000, sub{print $variable;});

MainLoop;

sub nickchange {
my $window2 = $fenster->Toplevel;
my $text = $window2->Label(-text => "Nickname eingeben")->pack();
my $entry = $window2->Entry()->pack();
my $button = $window2->Button(-text => 'Ok',-command => [\&action,$window2,$entry])->pack();
}


sub action {
my ($window2,$entry) = @_;
my $eingabe = $entry->get();
$window2->destroy();
$variable = $eingabe;
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Tk::Error: not a Tk object