0
之前訪問鍵文本:的Perl/Tk的:考慮下面的例子MainLoop語句
use strict;
use Tk;
my $w = tkinit;
$w->withdraw;
my $b = $w->Button(
-text => "Test",
-command => \&test,
)->pack();
$w->Popup;
print "Text: " . $b->cget(-text) . "\n";
MainLoop;
sub test
{
print "Text: " . $b->cget(-text) . "\n";
}
一旦程序開始我看到Text:
輸出,而不是Text: Test
。如果我按下按鈕,輸出是正確的。在調用MainLoop
之前,如何訪問按鈕屬性-text
?
的Perl,v5.10.1(*)建爲MSWin32 86多線程
Tk的版本:804.031
我不能說問題出在哪裏,但是您的代碼在Win 7 64上使用Strawberry Perl 5.12.3和Tk-804.032-1390844252工作。如果Perl已經安裝並使用「cpanp i Tk」來安裝Tk 。 – user3183018
也適用於我。 Tk 804.031,Perl 5.16.0,Linux。 – choroba
請打印到STDERR而不是STDOUT以避免輸出緩衝。 –