2011-11-17T16:48:19 KeanIch nutze bisher die Tk Funktion "messageBox" um einfache Abfragen zu realisieren.
Jetzt würde ich gerne eine eigene Messagebox mit Eingabefeldern realisieren
$rootwindow->waitWindow($thedialogwindow);
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
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); $mw->optionAdd("*font", "Arial 15 normal"); $mw->geometry("+250+200"); $mw->title("Example of Custom Dialog-Window"); my $btn1 = $mw->Button(-text => "Click button to open dialog-window.", -command => \&btnClick); $btn1->pack(-padx => 20, -pady => 20); my $btn2 = $mw->Button(-text => "Exit", -command => sub {$mw->destroy()}); $btn2->pack(-pady => 10); MainLoop(); sub btnClick { my $dialogwindow = $mw->Toplevel(); $dialogwindow->title("Dialog Window"); $dialogwindow->geometry("+300+250"); my $lab1 = $dialogwindow->Label(-text => "Please enter something:"); $lab1->pack(); my $entr1 = $dialogwindow->Entry(); $entr1->pack(); $entr1->focus(); my $btn3 = $dialogwindow->Button(-text => "Ok", -command => sub {dialogEnd($dialogwindow, $entr1)}); $btn3->pack(); # This is the important line: It tells the main-window to wait: $mw->waitWindow($dialogwindow); } sub dialogEnd { my $dialogwindow = shift; my $entr1 = shift; my $result = $entr1->get(); $dialogwindow->destroy(); $mw->messageBox(-title => "Input", -type => "OK", -message => "You entered:\n\n$result\n"); }