Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 如何在不使用子窗口的情况下调用另一个Tk窗口?_Perl_Perltk - Fatal编程技术网

Perl 如何在不使用子窗口的情况下调用另一个Tk窗口?

Perl 如何在不使用子窗口的情况下调用另一个Tk窗口?,perl,perltk,Perl,Perltk,我正在制作GUI(登录窗口)。密码正确后,登录窗口必须调用其他窗口。PerlTk中有没有办法调用另一个窗口而不是使用子窗口 use strict; use Tk; my $mw = MainWindow->new; $mw->geometry("300x150"); $mw->configure(-background=>'gray',-foreground=>'red'); $mw->title("PLEASE LOGIN"); my $main_fr

我正在制作GUI(登录窗口)。密码正确后,登录窗口必须调用其他窗口。PerlTk中有没有办法调用另一个窗口而不是使用子窗口

use strict;

use Tk;

my $mw = MainWindow->new;
$mw->geometry("300x150");
$mw->configure(-background=>'gray',-foreground=>'red');
$mw->title("PLEASE LOGIN");

my $main_frame=$mw->Frame(
    -background=>"gray",-relief=>"ridge",)->pack(-side=>'top',-fill=>'x');
my $left_frame=$main_frame->Frame(
    -background=>"gray")->pack(-side=>'left',-fill=>'x');
my $bottom_frame1=$mw->Frame(
    -background=>"gray")->pack(-side=>'bottom',-fill=>'x');
my $right_frame1=$mw->Frame(
    -background=>"gray")->pack(-side=>'left',-fill=>'x');


my $button=$bottom_frame1->Button(-text=>"OK",-command=>\&push_button);
$button->pack(-side=>'left');
my $cancel=$bottom_frame1->Button(-text=>"CANCEL",-command=>sub{$mw->destroy});
$cancel->pack(-side=>'right');
my $entry2=$mw->Entry(-width=>20,-relief=>"ridge")->place(-x=>100,-y=>75);

sub push_button{
   ...
   }

my $mw=MainWindow->new;
$mw->geometry("900x690");

你只需要单独的主窗口吗?构造每个主窗口后,就可以构造各种小部件来引用正确的变量。这是一个简短的程序,在一个主窗口中有一个按钮,在另一个主窗口中有一个按钮按下计数器:

#!/usr/local/bin/perl use Tk; # The other window as its own MainWindow # It will show the number of times the button # in the other window is pressed my $other_window = MainWindow->new; $other_window->title("Other Window"); my $other_frame = $other_window->Frame->pack( -fill => 'both' ); my $other_label = $other_frame->Label( -text => 'Pressed 0 times', )->pack( -side => 'top', -fill => 'x', ); # The login window as its own MainWindow my $login_window = MainWindow->new; $login_window->title("Login Window"); my $login_frame = $login_window->Frame->pack( -fill => 'both' ); my $login_label = $login_frame->Label( -text => 'Press the button', )->pack( -side => 'top', -fill => 'x', ); my $pressed = 0; my $login_button = $login_frame->Button( -text => 'Button', -command => sub { # references $other_label $pressed++; $other_label->configure( -text => "Pressed $pressed times" ); }, )->pack( -side => 'top', -fill => 'both', ); MainLoop; #!/usr/local/bin/perl 使用传统知识; #另一个窗口作为其自己的主窗口 #它将显示按钮的次数 #在另一个窗口中按 my$other\u window=main window->new; $other_window->title(“other window”); 我的$other\u框架=$other\u窗口->框架->包装( -填充=>'两个' ); 我的$other\u标签=$other\u框架->标签( -text=>“按了0次”, )->打包( -侧面=>“顶部”, -fill=>x', ); #登录窗口作为自己的主窗口 my$login\u window=main window->new; $login_window->title(“登录窗口”); 我的$login\u frame=$login\u window->frame->pack( -填充=>'两个' ); my$login\u label=$login\u frame->label( -text=>“按下按钮”, )->打包( -侧面=>“顶部”, -fill=>x', ); 我的$pressed=0; 我的$login\u按钮=$login\u框架->按钮( -text=>“按钮”, -command=>sub{#引用$other_标签 $pressed++; $other_label->configure(-text=>“Pressed$Pressed times”); }, )->打包( -侧面=>“顶部”, -fill=>“两者”, ); 主回路;
这段代码非常奇怪,因为你有这么多的use和require语句。这只是程序的一部分。即使代码正在运行,我也遇到了一些小问题。我认为还有另一种方法可以调用我的主窗口(GUI),或者运行其他程序,而不是使用子窗口,这样会使代码过长。这就是为什么我要问?你说的“调用其他GUI窗口”是什么意思?窗口是一个小部件,而不是一个子例程。你可以和它互动,但你不能“呼叫”它。