王朝网络
分享
 
 
 

Perl/TkFAQ-16.1如何使用对话框?

王朝perl·作者佚名  2008-05-18
宽屏版  字体: |||超大  

原文:

16.1. How do I get a Dialog box?

For things like a simple "are you sure?" dialog box you might want to take a look at perl5/Tk/Dialog.pm. This module may be invoked with require Tk::Dialog; etc. - there are much more extensive directions inside the comment fields at the top of the Dialog.pm file itself. The module has a lot of options and has a tutorial driver script in perl5/Tk/demos/dialog. Dialog.pm is also used by the perl5/Tk/demos/widget demo. In particular look at perl5/Tk/demos/widget_lib/dialog1.pl and dialog2.pl for examples of how one makes use of Tk::Dialog. A snippet of a script that uses this module could look like: require Tk::Dialog; my $mw = MainWindow->new; my $D = $mw->Dialog( -title => 'Are you sure?', -text => "You have requested rm \*\nAre you sure?", -default_button => 'No', -buttons => ['No','yes'] ); my $choice = $D->Show; # use Show for Tk-b9.01# if using Tk-b8: my $choice = $D->show; print " you chose $choice \n";

A question concerning configuration of the Subwidgets on the Dialogs came up recently: <Greg_Cockerham@avanticorp.com> wrote:! I want to reconfigure the colors of the Dialog and! ErrorDialog buttons. How do I do this?! Thanks in advance. $dialog_widget->configure(-background => 'purple');

Since these two widgets are composites you manage them like any 'ol widget. If the default delegate subwidget(s) aren't to your liking you can always get to individual component widgets of the composite via the ->Subwidget() method.

I see these subwidgets:

Dialog 'message' is the label subwidget with the dialog text, and 'bitmap' is the label subwidget showing the dialog bitmap ErrorDialog 'error_dialog' is Dialog subwidget, 'text' is text subwidget

You can even do things like this:

$error_dialog->Subwidget('error_dialog')-> Subwidget('bitmap')->configure(..);

to "get to" the label widget of the dialog component of the error_dialog widget.....

Be sure to also check out the "dialog" demo.

译文:

16.1 如何使用对话框?

对于只显示诸如“确定吗?”这样的简单信息的对话框窗口,你也许应该看一看perl5/Tk/Dialog.pm模块(译者注:可以在命令行中使用 perldoc Tk::Dialog来直接参看手册)。这个模块可以通过使用require Tk::Dialog;等方法引入,更多详细的介绍可以在Dialog.pm文件本身前部的注释区中找到。另外,这个模块还有很多选项,并且在 perl5/Tk/demos/dialog中还有一些演示脚本。同时,Dialog.pm也有相应当例子在widget演示程序中。特别是,可以通过 perl5/Tk/demos/widget_lib/dialog1.pl和dialog2.pl两个脚本,学习一下如何实际的使用Tk:: Dialog。下面是一个简单的使用这个模块的例子:

require Tk::Dialog;

my $mw = MainWindow->new;

my $D = $mw->Dialog(

-title => 'Are you sure?',

-text => "You have requested rm \*\nAre you sure?",

-default_button => 'No',

-buttons => ['No','yes']

);

my $choice = $D->Show;

print " you chose $choice \n";

最近有人提出了一个关于配置对话框的“子组件”(Subwidgets)的问题:

<Greg_Cockerham@avanticorp.com> 写到:

!我想重新配置对话框的颜色和错误信息框(ErrorDialog)的按钮。

!我应该如何如何实现?谢谢先。

$dialog_widget->configure(-background => 'purple');

虽然这两个组件都是复合组件,但是你也可以像对简单组件那样操作它们的。即使默认的代表子组件不是你所想要的,你也可以通过->Subwidget()方法来控制复合组件中的每一个元件。

对于这两个复合组件,我们可以看到如下的子组件:

Dialog

‘message’是标签子组件,用来显示对话框的文字;而’bitmap’也是一个标签子组件用来显示对话框的位图。

ErrorDialog

‘error_dialog’是一个对话框子组件;而’text’是一个文本子组件。

你甚至可以用下面的方法来配置error_dialog组件中对话框元件的标签组件:

$error_dialog->Subwidget('error_dialog')->

Subwidget('bitmap')->configure(..);

最后,请务必仔细参阅dialog的演示。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有