Google自訂搜尋

目前分類:Perl TK (7)

瀏覽方式: 標題列表 簡短摘要
先來Po我寫的範例吧(請自行寫出一個呼叫這個副常式的程式):

sub clicked_me(){
    my $msgbox=$main->messageBox(
        -message=>"Oh? Hi~",
        -title=>"Test",
        -type=>"yesno",
        -icon=>"warning",
        -default=>"no"
        );
}

我們先宣告一個變數,用來當作是MessageBox的widget
然後,我們把他新增到$main底下(之前就宣告好的主視窗widget)

底下是他的options

-default

這個就是當Message Box跳出來後,按紐焦點在哪個按鈕上

-icon

在X11下(也就是*nix or BSD)可以使用Tk內建的bmp圖片,但是在Windows下只能用error、info、question跟warning(也就是錯誤、資訊、問題跟警告)
而且我發現到一件很有趣的事情,error、info、question跟warning這四種在MessageBox跳出來時聲音都不一樣!自己去玩看看吧^^

-message

印出來的訊息

-title

就是標題拉

-type

按鈕的形式,像是 確定、確定 取消、重試 取消、放棄 重試 略過、是 否、是 否 取消

形式:

  1. OK
  2. OkCancel
  3. RetryCancel
  4. AbortRetryIgnore
  5. YesNo
  6. YesNoCancel

hechian 發表在 痞客邦 留言(0) 人氣()

選項通常都是要以'-'開頭,例如:-text
既然都是以'-'開頭,那我就省略不打囉..
  1. anchor -- 指明資訊如何顯示在widget中。子選項:
    1. n
    2. ne
    3. e
    4. se
    5. s
    6. sw
    7. w
    8. nw
    9. center
  2. background -- 指明當顯示widget時要使用的正常背景顏色
  3. bitmap -- widget中要顯示的點矩陣
  4. boarderwidth -- widget外邊要畫的3D邊界寬度
  5. cursor -- widget要用的滑鼠游標
  6. font -- widget內畫文字所要用的字型
  7. foreground -- widget要用的前景顏色
  8. geometry -- widget視窗所要的幾何
  9. highlightbackground -- widget沒有輸入焦點時在遊走突顯區域所要顯示的顏色
  10. highlightcolor -- widget有輸入焦點時用來遊走繞著widget所畫的突顯矩陣所用的顏色
  11. image -- widget中的影像
  12. insertbackground -- 由插入游標所涵蓋背景所要用的顏色
  13. justify -- 證明顯示widget中的多行文字
  14. orient -- 定位widget的方向,像是捲動軸
  15. padx -- 為widget在X方向請求多少空間
  16. pady -- 為widget在Y方向請求多少空間
  17. relief -- widget所要的3D效果
  18. selectbackground -- 當顯示選取的項目時,要用的背景顏色
  19. text -- 在widget內要顯示的字串
  20. textvariable -- 變數的名稱
  21. troughcolor -- 在widget內矩形槽區域所要用的顏色,像是捲動軸與尺度
  22. underline -- 在widget內要加底線字元的整數索引
  23. xscrollcommand -- 與水平捲動軸通訊的命令
  24. yscrollcommand -- 與垂直捲動軸通訊的命令

按鈕選項

  1. command -- 與按鈕結合的Tcl command
  2. selectimage -- 當一個check button被選取時要顯示的影像
  3. height -- 按鈕高度
  4. selectcolor -- 當一個Button被選取時要使用的背景顏色
  5. state -- 為一個radio button指定三個狀態之一:
    1. 正常
    2. 作用中
    3. 停止
  6. variable -- 要設定的全域變數,指出是否一個button被選取
  7. width -- 按鈕寬度

hechian 發表在 痞客邦 留言(0) 人氣()

  1. button -- a button
  2. canvas -- a paint window
  3. checkbutton -- a check button
  4. entry -- a input box
  5. frame -- a simple widget, for a container or spacer, in 複雜的視窗佈局
  6. image -- a widget for show image
  7. label -- a label
  8. listbox -- a list box
  9. menu -- a menu
  10. menubutton -- 一個存取選單的選單按鈕
  11. message -- a message
  12. radiobutton -- a radio button
  13. scrollbar -- a scrollbar
  14. text -- 可編輯的text box
  15. scale -- a scale

hechian 發表在 痞客邦 留言(0) 人氣()

事件運算:
  1. bind -- 結合Tcl Script and X events
  2. bindtags -- 結合commands to label
  3. selection -- 將widget放在一個frame中的位置
幾何管理員:
  1. pack -- 將widget包裝,彼此相鄰
  2. grid -- 將widget包裝,放在欄與列
  3. place -- 將widget放在一個frame中的位置
視窗運作:
  1. destroy -- Close a tk window
  2. toplevel -- Select a top-level window
  3. wm -- 設定Window特性
  4. uplevel -- 提升一個視窗層級

hechian 發表在 痞客邦 留言(0) 人氣()

#!/usr/bin/perl -w
use Tk;
use strict;

my $main=MainWindow->new;
my ($label, $text, $button);
$main->title('Test');
$label=$main->Label(
    -text=>'Test',
    -width=>10
    );
$text=$main->Entry(
    -width=>10);
$button=$main->Button(
    -text=>'Change',
    -command=>\&change);

foreach($label, $text, $button){
    $_->pack(-side=>"left",-fill=>"both");
}
MainLoop();

sub change(){
    $label->configure(-text=>$text->get());
}

hechian 發表在 痞客邦 留言(0) 人氣()

#!/usr/bin/perl
#宣告使用Tk
use Tk;
#使用嚴謹的語法
use strict;
#宣告一個變數供Tk建立視窗
my $main=MainWindow->new;
#設定視窗標題
$main->title('New Window');
#顯示視窗
MainLoop();

hechian 發表在 痞客邦 留言(0) 人氣()

#!/usr/bin/perl -w
use Tk;
use strict;

my $main=MainWindow->new;
my ($n1,$n2,$add,$eq,$result);
$main->title('Test');
$n1=$main->Entry(-width=>3);
$n2=$main->Entry(-width=>3);
$result=$main->Entry(-width=>4);
$add=$main->Label(
    -text=>'+');
$eq=$main->Button(
    -text=>'=',
    -command=>\&do_it);
foreach ($n1, $add, $n2, $eq, $result){
    $_->pack(-side=>"left", -fill=>"both");
}
MainLoop();

sub do_it(){
    my $sum=$n1->get()+$n2->get();
    $result->configure(-text=>$sum);
}

hechian 發表在 痞客邦 留言(0) 人氣()