Thread Tk: ein Tk::Toplevel bei MainLoop() nicht zeigen
(3 answers)
Opened by moritz at 2008-03-13 17:09
So könnte eine einfache Klasse aussehen:
Code (perl): (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 43 44 45 46 47 48 49 50 51 package Tk::MyTest; require Tk; require Tk::Toplevel; require Tk::HList; our @ISA = qw(Tk::Derived Tk::Toplevel); our $VERSION = '0.04'; Construct Tk::Widget 'MyTest'; sub Show{ my ($cw) = @_; $cw->Popup(); $cw->waitVariable(\$cw->{Selected}); $cw->withdraw; $cw->{Selected} = [""] unless(defined $cw->{Selected}); return wantarray ? @{$cw->{Selected}} : join("; ",@{$cw->{Selected}}); }# Show sub Populate{ my ($cw,$args) = @_; $cw->SUPER::Populate($args); my $hl = $cw->Component('ScrlListbox' => 'test', -width => 40, -scrollbars => 'ose', -selectmode => 'single', -exportselection => 0, -font => 'Courier 8', ); for(1..10){ $hl->insert('end',$_); } $hl->pack(); $hl->bind('<Double-1>' => [$cw => 'Accept']); return $cw; }# Populate sub Accept{ my ($cw) = @_; my $ref = [$cw->Subwidget('test')->Getselected()]; $ref = [""] unless($ref); $cw->{Selected} = $ref; }# Accept 1; Und hier ein Testskript: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/usr/bin/perl use strict; use warnings; use lib qw(perllib); use Tk; use Tk::MyTest; my $mw = tkinit; $mw->Button( -command => \&test, -text => 'testen' )->pack; MainLoop; sub test{ my $diag = $mw->MyTest; my $retval = $diag->Show; warn $retval; } Erst auf den Button klicken und dann ein Doppelklick auf irgendeine Zahl... 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/ |