2

我遇到了一个我相信 Perl/Tk 804.027 Text Widget 的错误(使用Scrollable('ROText'))。当我添加一个全选标签并应用配置更改以向右对齐时,滚动条不会显示。如果我注释掉我向右对齐的 tagConfigure,滚动条就会回来。

有没有人有一种解决方法或修复方法来正确证明文本小部件的内容(包括文本和嵌入式条目小部件)并且仍然具有功能性水平滚动条?

(更新)

这是一个将重现该问题的示例脚本:

use Tk;

$mw = MainWindow->new;
$mw->title("Testing");
$mw->geometry();

$pw = $mw->Scrolled('Panedwindow',-showhandle=>0, -sashwidth=>0, -sashpad=>0, -scrollbars=>'e');

$pw->pack(qw/-side top -expand yes -fill both -pady 2 -padx 2m/);

$t1 = $pw->Scrolled("Text", -scrollbars => 'os', -bg=>"red", -width => 40, -wrap => "none", -relief=>"flat");
$t2 = $pw->Scrolled("Text", -scrollbars => 'os', -bg=>"blue", -width => 20, -wrap => "none", -relief=>"flat");

$pw->add($t1,$t2);

# this loop is only to demonstrate the second problem: vertical scrolling 
# on parent widget not working
foreach my $ct (1..50) {
$t1->insert("end","abcdef-abcdef-abcdef-abcdef-abcdef-abcdef-abcdef-abcdef-abcdef-abcdef\n");
 }
$t1->tagAdd("content", '1.0', 'end');


# this is the justify right & loose horizontal scrolling problem:
# change the justify from left to right and the scrollbars will not show up
$t1->tagConfigure("content", -justify=>"left");

MainLoop;

对于我的应用程序来说,我遇到的问题实际上是双重的,并且在上面的示例中都证明它们都不起作用:

  1. 我需要窗格的左侧水平滚动和右对齐
  2. 我需要 Paned Window 小部件(两个窗格的父级)可以垂直滚动(左右窗格一起滚动)。
4

1 回答 1

0

我发现当我认为别人的代码中存在错误时,生成一个复制该行为的非常小的程序通常会有所帮助。我通常通过这个过程发现错误来自我对代码的使用,而不是来自代码本身(这并不奇怪,因为与旧代码不同,新代码从未被其他人测试或使用过)。

在许多棘手的应用程序代码中通常很难看到您的错误。通过将其分离成一个简单的测试用例,您可以消除问题中的噪音。而且,如果问题仍然存在,您有一个测试用例,您可以向作者报告或发布到类似这样的网站。

于 2010-05-27T11:54:20.153 回答