文本元素的缓冲/更新问题
我有这样的代码:
#!/usr/bin/perl
use strict;
use Tkx;
my $mw = Tkx::widget->new('.');
$mw->g_wm_minsize( 400, 350 );
my $btn_start = $mw->new_ttk__button( -text => "Start", -width => 60, -command => sub { start(); } );
my $txt_processed_domains = $mw->new_tk__text( -width => 40, -height => 10, -state => "disabled", -wrap => "none" );
Tkx::grid( $btn_start, -row => 2, -columnspan => 3, -padx => 10, -pady => 10 );
Tkx::grid( $txt_processed_domains, -row => 3, -columnspan => 3, -padx => 10, -pady => 10 );
Tkx::MainLoop();
sub start {
foreach my $id ( 1.. 10 ) {
$txt_processed_domains->configure(-state => "normal");
$txt_processed_domains->insert_end( "$id => Available\n" );
$txt_processed_domains->configure(-state => "disabled");
sleep 1;
}
Tkx::tk___messageBox( -message => "Completed!" );
}
我需要查看哪些 id 被处理,但最后只得到整个列表。这就像用文件句柄缓冲,但我不确定。如何在文本框中插入文本后立即看到文本?
I have this code:
#!/usr/bin/perl
use strict;
use Tkx;
my $mw = Tkx::widget->new('.');
$mw->g_wm_minsize( 400, 350 );
my $btn_start = $mw->new_ttk__button( -text => "Start", -width => 60, -command => sub { start(); } );
my $txt_processed_domains = $mw->new_tk__text( -width => 40, -height => 10, -state => "disabled", -wrap => "none" );
Tkx::grid( $btn_start, -row => 2, -columnspan => 3, -padx => 10, -pady => 10 );
Tkx::grid( $txt_processed_domains, -row => 3, -columnspan => 3, -padx => 10, -pady => 10 );
Tkx::MainLoop();
sub start {
foreach my $id ( 1.. 10 ) {
$txt_processed_domains->configure(-state => "normal");
$txt_processed_domains->insert_end( "$id => Available\n" );
$txt_processed_domains->configure(-state => "disabled");
sleep 1;
}
Tkx::tk___messageBox( -message => "Completed!" );
}
I need to see which ids are processed but only get whole list at the end. It's like buffering with filehandles but i'm not sure. How to see text in the text box just after inserting it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现
Tkx::update();
做我想做的事。I find
Tkx::update();
do what i want.在这种情况下,Tkx::update_idletasks() 将是首选调用。
Tkx::update_idletasks() would be the preferred call in this case.