亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 7923 | 回復: 2
打印 上一主題 下一主題

求助:如何讓perl/Tk主窗口關閉(點擊主窗口右上方的關閉按鈕)時執(zhí)行特定的子例程 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2012-08-29 12:43 |只看該作者 |倒序瀏覽
各位大俠幫忙一下: 如何讓perl/Tk主窗口關閉時執(zhí)行特定的子例程

目的:在主窗口中有一個Text控件,在關閉主窗口(即mouse點擊主窗口右上方的關閉按鈕的時候)可以執(zhí)行一個子例程,用來保存Text控件的內容
如果用一個Button來關聯是可以的,就是不知道如何在點擊主窗口右上方的關閉按鈕的時候實現同樣的功能


button關聯的實現是這樣的:
my $button20 = $frame->Button(-text=>decode('utf-8',"退  出"),-fg=>"red",-font => "fixed 12 bold",-command =>\&leave);
sub leave {
        my $str = $txt->Contents();
        my $file = time;
        system("echo -e \" $str\" >/var/log/mylog${file}");
        exit;
        }

論壇徽章:
0
2 [報告]
發(fā)表于 2012-08-29 16:24 |只看該作者
回復 1# aoma


    很久沒寫Tk了,手頭沒有環(huán)境,試試:
  1. $frame->protocol('WM_DELETE_WINDOW' => \&leave);
復制代碼

論壇徽章:
0
3 [報告]
發(fā)表于 2012-08-29 19:32 |只看該作者
是的,你的語句真的行,謝謝kk861123兄

我在后面加了一行就可以了
因為frame是建立在主窗口上的,因此我下面的語句是可行,已驗證了
$mw->protocol('WM_DELETE_WINDOW' => \&leave);

下面找到的Master perl/Tk中有關protocol的參考

The protocol method controls the following window properties: WM_DELETE_WINDOW, WM_SAVE_YOURSELF, and WM_TAKE_FOCUS. The callback (if any) associated with each property will be invoked when the window manager recognizes the event associated with the property:

$toplevel->protocol ( [ property_name] [, callback ] );
The WM_DELETE_WINDOW property callback is invoked when the window has been deleted by the window manager. By default, there is a callback assigned by Perl/Tk that destroys the window. If you assign a new callback, your callback will be invoked instead of the default callback. If you need to save data associated with that window, do so in the callback, then invoke $toplevel->destroy() to mimic the correct behavior afterward.

The other two properties, WM_SAVE_YOURSELF and WM_TAKE_FOCUS, are used much less commonly. For instance, WM_TAKE_FOCUS is used in Unix systems but not in Win32. The presence of these properties is dependent on the window system you are running. If your application will be running on multiple systems, don't expect these properties to always be available. To find out if they are available, assign each one a callback that does a print, then run the application to see if the print is ever invoked.

If you leave out the callback when you use protocol, the current callback assigned to that property will be returned (or an empty string, if there isn't a current callback assigned). You can remove the callback by sending an empty string instead of the callback. If neither argument is specified, the method returns a list of all properties that have callbacks assigned to them.


您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯網協會會員  聯系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP