TK之button

分为三种类型: Button,CheckButton,RadioButton.

 

Button:The -text option lets the user know what the Button is for, and the -command option makes something happen when the user clicks the Button.

 

Checkbuttons:Using -variable gives you an easy way to find out whether the Checkbutton is checked

 

eg:$mw->Checkbutton(-text => 'Print Header', -variable => /$print_header);

 

 

When creating Radiobuttons, we always create more than one and use the -text , -variable , and -value options:

$group1 = 100; # set default value

foreach (qw/1 10 100 10000 100000 1000000/) {

$mw->Radiobutton(-text => '$' . $_, -variable => /$group1,

-value => $_)->pack(-side => 'left');

}



print "User selected: $group1";






Option

Button

Checkbutton

Radiobutton

-activebackground => color
Sets the color the background should be when the mouse cursor is over the Button. A color is a text string such as "red" .

-activeforeground => color
Sets the color the text should be when the mouse cursor is over the Button.

-anchor => 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | 'center'
Causes the text to stick to the specified position in the Button.

-background => color
Sets the background of the Button to color .

-bitmap => 'bitmapname'
Sets default bitmap or the location of a bitmap file (with @ in front of path). See Chapter 17, "Images and Animations" for more details.

-borderwidth => amount
Changes the width of the edge drawn around the Button and the thickness of the indicator. Emphasizes the -relief of the Button.

-command => callback
Indicates a pointer to a function that will be called when the Button is pressed.

-cursor => 'cursorname'
Indicates that the mouse cursor will change to 'cursorname' when over the Button. See Chapter 23, "Plethora of pTk Potpourri" for details.

-disabledforeground => color
Sets the color the text should be when the Button is disabled ( -state will be 'disabled' ).

-font => 'fontname'
Changes the font of all text on the Button.

-foreground => color
Changes the text color to color .

-height => amount
Sets the height of the Button in characters if text is displayed and the screen distance if an image or bitmap is displayed.

-highlightbackground => color
Sets the color of the area behind the focus rectangle (shows when widget does not have focus).

-highlightcolor => color
Sets the color of the focus rectangle (shows when widget has focus).

-highlightthickness => amount
Sets the thickness of the highlight rectangle around the Button; indicates focus.

-image => $imgptr
$imgptr is a pointer to an Image object made with any supported image format. See Chapter 17, "Images and Animations" for details.

-indicatoron => 0 | 1
Determines whether to display the indicator.
 

-justify => 'left' | 'right' | 'center'
Sets the direction against which multiline text will justify.

-offvalue => newvalue
Sets the value used when the Button is off. Must be a scalar. Default is 0.
 

 
-onvalue => newvalue
Sets the value used when the Button is on. Must be a scalar. Default is 1.
 

 
-padx => amount
Adds extra space to the left and right side of the Button inside the Button edge.

-pady => amount
Adds extra space to the top and bottom of the Button inside the Button edge.

-relief =>'flat'|'groove'|'raised'|'ridge'|'sunken'|'solid'
Changes the type of edges drawn around the Button. Default for Checkbutton and Radiobutton is 'flat' .

-selectcolor => color
Sets the color of the indicator when on.
 

-selectimage => imgptr
Indicates the image to display instead of text when Button is on. Ignored if -image is not used.
 

-state => 'normal' | 'disabled' | 'active'
Indicates the Button's state of responsiveness. If set to 'disabled' , the Button does not respond.

-takefocus => 0 | 1 | undef
Indicates that the Button will never get focus (0), always get focus (1), or let the application decide ( undef ).

-text => 'text'
Sets the text string displayed on the Button.

-textvariable => /$variable
Points to a variable containing text to be displayed in Button. Button text will change as $variable does.

-underline => n
Underlines the n th character in the text string. Allows keyboard input via that character when Button has the focus. It's important to note that the character is only underlined; any behavior must be supplied by the programmer via a bind command. See Chapter 15, "Anatomy of the MainLoop" for binding details.

-value => newvalue
Sets the value assigned to $variable (with -variable option) when this Radiobutton is selected. Default is 1.
   

-variable => /$value
Associates the on/off values with $variable .
 

-width => amount
Sets the width of the Button in characters if text is displayed and as a screen distance if an image or bitmap is displayed.

-wraplength => amount
Sets the screen distance for the maximum amount of text displayed on one line. The default is 0, which means that text is not wrapped at word boundaries, only at line breaks (newlines).

 


如何在button中添加图片:



$image = $mw->Photo(-file => "bigredbutton.gif");

$mw->Button(-text => 'Exit', -command => sub { exit },

-image => $image)->pack;





With Radiobuttons, there is no default value, and you need to explicitly assign

$value
with the -value
option


修改button的风格:
flat
No edges are drawn around the Button at all. Makes it look like only text is present in the window.
groove
Gives a slightly depressed look to the edge (as if there were a ditch around the text).
raised
Gives a 3D look with a shadow on the lower and right sides of the Button, which causes it to look higher than the window surface. This is the default.
ridge
Makes it look like a ridge is around the text. The opposite of 'groove' .
solid
Draws a solid line around the widget.
sunken
Gives the 3D effect of being below the surface of the window. The opposite of 'raised'
 
  

 

 

 

 

你可能感兴趣的:(perl语言,button,radiobutton,distance,character,image,header)