原文:
11.2. Erase a display?
To erase something like a bitmap call delete on the item. Assuming your Canvas tag is $canvar and your item tag it $bittag (as in the previous [11.1] question) then the call proceeds like: $canvar -> delete($bittag);
This is of course useful in a callback. For example to configure a Button to do your deletion for you you could say something like: $main->Button(-text => 'clear', -command=>sub{$canvar -> delete($bittag)} )->pack;
To remove an entire MainWindow() call the withdraw() method: $main -> withdraw;
译文:
11.2. 如何擦除画布上的元素?
要从画布上删除元素,如位图等,可以对它调用delete方法。假设你的画布组件的变量叫$canvar,而你要删除的元件的变量是$bittag(就像在前面的11.1中定义的那样),那么我们可以这样使用:
$canvar -> delete($bittag);
当然,这如果定义在一个回应函数中会比较有用。例如,要想设置一个按钮来进行删除工作,就可以这样:
$main->Button(-text => 'clear',
-command=>sub{$canvar -> delete($bittag)}
)->pack;
要想去掉整个主窗口(MainWindow),需要调用withdraw()方法:
$main->withdraw;
(译者注:这样的方法,顾名思义,只是把主窗口收缩隐藏了,其实并没有真正删除——真删除要用destroy,不过那样程序也就退出了——所以还可以使用 deiconify方法让主窗口重新显示出来,比如说也设置一个按钮,但是这个按钮就不能放在主窗口里了,一般是诸如Toplevel之类的其它窗口中。)