Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get default options of Tk widgets

2 views
Skip to first unread message

Simon Bachmann

unread,
Apr 29, 2006, 10:46:48 AM4/29/06
to
Hi

% info patchlevel
8.4.11

My question: is there a way to get the values that are used for options
of Tk widgets when they aren't specified? (the defaults)
Is there a command or a variable that can tell me, for instance, what
background color is used by default for Labels?
The "option get" command isn't what I'm looking for: it works for some
options, it doesn't for others:

% option get . font Label
helvetica -12
% option get . Foreground Label
%

That's what I'm trying to do:
I've got a proc that configures several widgets according to data stored
in arrays/lists.
This works well, now I need to "reset" some options of this widgets to
the default value. The problem is that I cannot know in advance what
options are to be reset, so I can't use hardcoded values...

Here's a simplified example of what I'm looking for

label .l -fg red

set option foreground
.l configure -$option {Here I need the default value...}

Of course I could create an array that contains all values that I need,
but if there's an easier way...

Tnx

Simon

Michael Schlenker

unread,
Apr 29, 2006, 11:25:56 AM4/29/06
to
Simon Bachmann schrieb:

Usually one creates one widget of the appropriate type and uses
configure to read the default values of the options.

Michael

Uwe Klein

unread,
Apr 29, 2006, 11:26:46 AM4/29/06
to
Hi,
is this what you are looking for?

set widget [ label .l]
set alloptions [ $widget configure ]
set singleoption [ $widget configure -$option ]

foreach item $alloptions {
foreach {argname optdbname class default current} $item {
puts "cmdline name : $argname"
puts "optdbname : $optdbname"
puts "Class : $class"
puts "default val : \"$default\""
puts "current val : \"$current\""
puts ""
}
}

set option [ string trimleft $argname - ]
set singleoption [ $widget configure -$option ]

puts "singleoption \"$option\""

foreach {argname optdbname class default current} $singleoption {
puts "cmdline name : $argname"
puts "optdbname : $optdbname"
puts "Class : $class"
puts "default val : \"$default\""
puts "current val : \"$current\""
puts ""
}


uwe

Simon Bachmann

unread,
Apr 29, 2006, 2:40:23 PM4/29/06
to
>
>
> Usually one creates one widget of the appropriate type and uses
> configure to read the default values of the options.
>
> Michael

I already considered this, I thought there might be a more "elegant"
solution....
But you're right, it's a really simple way, and exactly what I want.

tnx

Simon

0 new messages