canvas教程

Tk中用Canvas绘图,Scrollbar不起作用

字号+ 作者:H5之家 来源:H5之家 2018-02-14 12:27 我要评论( )

Tk中用Canvas绘图,Scrollbar不起作用

  • <p>use Tk;
  • use utf8;
  • $mw = MainWindow->new( );
  • $mw->geometry("300x100");#1368
  • $mw->title("模式关系网");#
  • $mw->title("One Scrollbar/Three Listboxes");
  • $mw->Button(-text => "Exit",
  •             -command => sub { exit })->pack(-side => 'bottom');

  • $scltest = $mw->Scrollbar( );

  • $canvas =  $mw->Canvas();


  • sub scroll_canvas {
  •   my ($scltest, $canvas,  @args) = @_;
  •   $scltest->set(@args);

  • }


  • $canvas->configure(-yscrollcommand => [ \&scroll_canvas, $scltest,
  •                                        $canvas, ]);


  • # Configure the Scrollbar to scroll each Listbox
  • $scltest->configure(-command => ['yview' => $canvas]);

  • # Pack the Scrollbar and Listboxes

  • $scltest->pack(-side => 'left', -fill => 'y');

  • $canvas->pack(-side => 'left');

  • my $bt102 = $canvas->Button(-text => "下个方法",
  •                         -command => \&printinfo);

  • my $id102 = $canvas->createWindow(36,30, -window =>$bt102);

  • my $bt103 = $canvas->Button(-text => "上个方法",
  •                         -command => \&printinfo);


  • my $id104 = $canvas->createWindow(36,200, -window =>$bt104);


  • my $bt105 = $canvas->createLine( 30,40,400,400, -fill =>  "green"
  •                         );

  • MainLoop;

  • sub printinfo
  • {
  •          print "ok!\n";
  • }</p><p>
  • </p><p>但是下面的代码是有效的:</p><p>
  • </p><p>use Tk;</p><p>$mw = MainWindow->new( );
  • $mw->geometry("200x200");#1368
  • $mw->title("模式关系网");#
  • $mw->title("One Scrollbar/Three Listboxes");
  • $mw->Button(-text => "Exit",
  •             -command => sub { exit })->pack(-side => 'bottom');</p><p>$scltest = $mw->Scrollbar( );</p><p>$txt =  $mw->Text();</p><p># This method is called when one Listbox is scrolled with the keyboard
  • # It makes the Scrollbar reflect the change, and scrolls the other lists
  • sub scroll_Text {
  •   my ($scltest,   @args) = @_;
  •   $scltest->set(@args); # tell the Scrollbar what to display $lbs,

  • }</p><p>
  • $txt->configure(-yscrollcommand => [ \&scroll_Text, $scltest,
  •                                         ]);$txt, </p><p>
  • # Configure the Scrollbar to scroll each Listbox
  • $scltest->configure(-command => sub {
  •                                        $txt->yview(@_);
  •                                      });</p><p># Pack the Scrollbar and Listboxes
  • $scltest->pack(-side => 'left', -fill => 'y');
  • $txt->pack(-side => 'left');</p><p>$txt->insert('end', "one", "eight", "nine", "The first argument is the numberof units to scroll by.
  •                The value for number can be any number, but it's typically either 1 or -1. A value of
  •                1 means the next unit of data on the bottom or right of the widget becomes visible
  •                (scrolling one unit of data off the left or top). A value of -1 means that a previous
  •                unit of data will become visible in the top or right of the widget (one unit will scroll
  •                off the bottom or right of the widget). For example, every time the user clicks on the
  •                down arrow in a vertical Scrollbar
  •                associated with a Listbox, a new line shows up at the bottom of the Listbox. ",
  •                "This form is used when the user clicks on the slider,
  •                moves it around, and drops it again. The argument is a fraction, a real number from 0 to 1
  •                that represents the first part of the data to be shown within the widget. If the user moves
  •                the slider all the way to the top or left of the Scrollbar, the very first part of the data
  •                in the widget should be seen on the screen. This means the argument should be 0:");</p><p>
  • MainLoop;</p><p>
  • </p><p>
  • </p>

     

  • 1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    相关文章
    • HTML5 Canvas 基础API和实例

      HTML5 Canvas 基础API和实例

      2018-02-14 13:27

    • canvas 像素操作

      canvas 像素操作

      2018-02-14 10:10

    • 用Canvas做视频拼图

      用Canvas做视频拼图

      2018-02-14 08:27

    • HTML5 Canvas实现web画图之自由画笔

      HTML5 Canvas实现web画图之自由画笔

      2018-02-13 18:24

    网友点评