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

Chinaunix

標(biāo)題: 求助:如何讓perl/Tk主窗口關(guān)閉(點(diǎn)擊主窗口右上方的關(guān)閉按鈕)時執(zhí)行特定的子例程 [打印本頁]

作者: aoma    時間: 2012-08-29 12:43
標(biāo)題: 求助:如何讓perl/Tk主窗口關(guān)閉(點(diǎn)擊主窗口右上方的關(guān)閉按鈕)時執(zhí)行特定的子例程
各位大俠幫忙一下: 如何讓perl/Tk主窗口關(guān)閉時執(zhí)行特定的子例程

目的:在主窗口中有一個Text控件,在關(guān)閉主窗口(即mouse點(diǎn)擊主窗口右上方的關(guān)閉按鈕的時候)可以執(zhí)行一個子例程,用來保存Text控件的內(nèi)容
如果用一個Button來關(guān)聯(lián)是可以的,就是不知道如何在點(diǎn)擊主窗口右上方的關(guān)閉按鈕的時候?qū)崿F(xiàn)同樣的功能


button關(guān)聯(lián)的實現(xiàn)是這樣的:
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;
        }

作者: kk861123    時間: 2012-08-29 16:24
回復(fù) 1# aoma


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

作者: aoma    時間: 2012-08-29 19:32
是的,你的語句真的行,謝謝kk861123兄

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

下面找到的Master perl/Tk中有關(guān)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.



作者: 唐勝    時間: 2018-04-17 10:11
my $mw = MainWindow->new( -title =>123);       
$mw->protocol("WM_DELETE_WINDOW", \&OnQuit);                ##設(shè)置退出執(zhí)行
sub OnQuit {
                                ##執(zhí)行代碼
}




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2