| Previous | Next
Miscellaneous Perl/Tk MethodsContents:Managing Widgets with configure and cget
So far, most of the chapters in this tutorial have concentrated on specific widgets. This chapter covers the methods and subroutines that can be invoked from any widget. You'll probably never need most of these methods, but there are a few that you'll use frequently, particularly Most of the methods are based on the Tcl This chapter also documents clipboard and selection methods for cut-and-paste operations between applications, focus and grab methods, and a few esoteric goodies. Managing Widgets with configure and cgetEvery widget included in the Perl/Tk distribution, as well as all user-contributed widgets available separately, can use the The The configure MethodThe basic format of the $widget->configure( [ Depending on the arguments passed to it, the
To set or change the value of an option, send the option pair exactly as it would have appeared in the widget creation command: $widget->configure( Whatever effect the option has will take place immediately. To see the current values for a single option, send it as the argument. The return value depends on whether @info = $widget->configure(-highlightthickness); In list context, an array of scalars is returned: -highlightthickness highlightThickness HighlightThickness 2 2 The following five values are in the returned array:
Calling If you want to see the list of values for all the options the widget supports, use this format: @config = $widget->configure;
use Tk::Pretty; @config = $widget->configure; print Pretty @config; The result is as follows: ['-activebackground',activeBackground,Foreground,'#ececec','#ececec'], ['-activeforeground',activeForeground,Background,Black,Black],['-activeimage', activeImage,ActiveImage,undef,undef],['-anchor','anchor',Anchor,'center', 'center'],['-background','background',Background,'#d9d9d9','#d9d9d9'],['-bd', borderWidth],['-bg','background'],['-bitmap','bitmap',Bitmap,undef,undef], ['-borderwidth',borderWidth,BorderWidth,2,2],['-command','command',Command, undef,bless([CODE(0x8189888)],Tk::Callback)],['-cursor','cursor',Cursor, undef,undef],['-disabledforeground',disabledForeground,DisabledForeground, '#a3a3a3','#a3a3a3'],['-fg','foreground'],['-font','font',Font,'-Adobe -Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*','-Adobe-Helvetica-Bold-R-Normal --*-120-*-*-*-*-*-*'],['-foreground','foreground',Foreground,Black,Black], ['-height','height',Height,0,0],['-highlightbackground',highlightBackground, HighlightBackground,'#d9d9d9','#d9d9d9'],['-highlightcolor',highlightColor, HighlightColor,Black,Black],['-highlightthickness',highlightThickness, HighlightThickness,2,2],['-image','image',Image,undef,undef],['-justify', 'justify',Justify,'center','center'],['-padx',padX,Pad,3m,9],['-pady',padY, Pad,1m,3],['-relief','relief',Relief,'raised','raised'],['-state','state', State,'normal','normal'],['-takefocus',takeFocus,TakeFocus,undef,undef], ['-text','text',Text,undef,Do_Something],['-textvariable',textVariable, Variable,undef,undef],['-underline','underline',Underline,-1,-1],['-width', 'width',Width,0,0],['-wraplength',wrapLength,WrapLength,0,0] Although this list may look nasty and ugly, it distinguishes between the different lists of lists for you by adding the You may find the output of Data::Dumper more pleasing: use Data::Dumper; @config = $widget->configure; print Dumper @config; Producing output similar to this: $VAR22 = [ '-highlightthickness', 'highlightThickness', 'HighlightThickness', '1', 1 ]; The configuration options for each widget described in this tutorial are listed in Appendix B, " Options and Default Valuesfor Each Widget". The cget MethodInstead of using $widget->cget(-option) It returns only the current value (or address if the option stores a reference) of the option rather than the entire list that
|