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

Strange TTK vs TK behavior

120 views
Skip to first unread message

Gerhard Reithofer

unread,
Nov 3, 2012, 8:08:15 AM11/3/12
to
Hi TLCers,
from an example some time ago in this newsgroup I found some strange
behavior:

package require Tk
pack [entry .e -textvariable yourtext] -expand yes -fill x
pack [button .b -command Doit -text "Press"]
proc Doit {} {
variable yourtext
tk_messageBox -message "You pressed, text is $yourtext"
}

Runs as expected, but the same script with ttk (as shown in the
example):

package require Tk
pack [ttk::entry .e -textvariable yourtext] -expand yes -fill x
pack [ttk::button .b -command Doit -text "Press"]
proc Doit {} {
variable yourtext
tk_messageBox -message "You pressed, text is $yourtext"
}

Throws an error, if there is no text in the entry:
can't read "yourtext": no such variable
while executing
"tk_messageBox -message "You pressed, text is $yourtext""
(procedure "Doit" line 3)
invoked from within
"Doit"
invoked from within
".b invoke "
invoked from within
".b instate !disabled { .b invoke } "
invoked from within
".b instate pressed { .b state !pressed; .b instate !disabled { .b
invoke } } "
(command bound to event)

% info patchlevel
8.5.11
% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine) = x86_64
tcl_platform(os) = Linux
...

Is that inteded?
Is this a (known) bug?

After you write some text into the entry it reacts correctly, even if
you erase the text (backspace).

--
Gerhard Reithofer
Tech-EDV Support Forum - http://support.tech-edv.co.at

Christian Gollwitzer

unread,
Nov 3, 2012, 9:22:25 AM11/3/12
to
Am 03.11.12 13:08, schrieb Gerhard Reithofer:
> Hi TLCers,
> from an example some time ago in this newsgroup I found some strange
> behavior:
>
> package require Tk
> pack [entry .e -textvariable yourtext] -expand yes -fill x
> pack [button .b -command Doit -text "Press"]
> proc Doit {} {
> variable yourtext
> tk_messageBox -message "You pressed, text is $yourtext"
> }
>
> Runs as expected, but the same script with ttk (as shown in the
> example):
>
> package require Tk
> pack [ttk::entry .e -textvariable yourtext] -expand yes -fill x
> pack [ttk::button .b -command Doit -text "Press"]
> proc Doit {} {
> variable yourtext
> tk_messageBox -message "You pressed, text is $yourtext"
> }
>
> Throws an error, if there is no text in the entry:
> can't read "yourtext": no such variable

I don't know whether it is intended, but the reason is simply that
ttk::entry does not touch the variable until you first use it. As it has
not been set in the code, it is unset until you first put something into
the box. In order to fix this, put

set yourtext {}

into the code.

For an entry, this might not be very useful. However, radiobuttons and
checkboxes use unset variables for tri-state information. Unfortunately,
there is a bug in the X11 versions of Tk that the third state is not
displayed correctly. On Win&Aqua, however, this displays a checkbutton
with an initial "undecided" third state:

pack [ttk::checkbutton .c -text "Undecided" -variable notinitialized]


Christian


Harald Oehlmann

unread,
Nov 5, 2012, 3:01:09 AM11/5/12
to
IMHO it is a bug. This should not throw an error.
Please file a bug report.
Thanks,
Harald

Gerhard Reithofer

unread,
Nov 5, 2012, 1:12:30 PM11/5/12
to
Hi Christian,

On Sat, 3 Nov 2012, Christian Gollwitzer wrote:

> Am 03.11.12 13:08, schrieb Gerhard Reithofer:
> > Hi TLCers,
> > from an example some time ago in this newsgroup I found some strange
> > behavior:

...

> > Throws an error, if there is no text in the entry:
> > can't read "yourtext": no such variable
>
> I don't know whether it is intended, but the reason is simply that ttk::entry
> does not touch the variable until you first use it. As it has not been set in
> the code, it is unset until you first put something into the box. In order to
> fix this, put
>
> set yourtext {}
>
> into the code.

ok, is this a workaround or solution?
If it is not intended, then it's just a workaround ;)

> For an entry, this might not be very useful. However, radiobuttons and
> checkboxes use unset variables for tri-state information. Unfortunately, there
> is a bug in the X11 versions of Tk that the third state is not displayed
> correctly. On Win&Aqua, however, this displays a checkbutton with an initial
> "undecided" third state:
>
> pack [ttk::checkbutton .c -text "Undecided" -variable notinitialized]

This is another "problem", isn't it?
Ttk checkbox doesn't have -tristate option, Tk has it.
Therefore I would call the Win&Aqua behavior as bug.

And to increase the confusion completely:
Test on Windows XP, Tcl8.6b1.2

package require Tk
pack [checkbutton .c -variable var -tristatevalue 2]
set var 2

After creation the state is "unchecked", when setting var to the
tristate value 2 the checkbox is changed to "checked", not tristate!

On 8.6b3 the same works on Linux.

Q: 3 bugs to file?

Christian Gollwitzer

unread,
Nov 6, 2012, 1:55:41 AM11/6/12
to
Am 05.11.12 19:12, schrieb Gerhard Reithofer:
> On Sat, 3 Nov 2012, Christian Gollwitzer wrote:
>>For an entry, this might not be very useful. However, radiobuttons and
>> checkboxes use unset variables for tri-state information. Unfortunately, there
>> is a bug in the X11 versions of Tk that the third state is not displayed
>> correctly. On Win&Aqua, however, this displays a checkbutton with an initial
>> "undecided" third state:
>>
>> pack [ttk::checkbutton .c -text "Undecided" -variable notinitialized]
>
> This is another "problem", isn't it?
> Ttk checkbox doesn't have -tristate option, Tk has it.
> Therefore I would call the Win&Aqua behavior as bug.

Definitely not a bug! It is documented in the manual

http://www.tcl.tk/man/tcl/TkCmd/ttk_checkbutton.htm#M9
http://www.tcl.tk/man/tcl/TkCmd/ttk_radiobutton.htm#M9

and e.g. used in the commercial software I was involved last year.
Unsetting the variable puts the widget into alternate state. This was a
design decision - don't know why, maybe Joe English can explain.
It works also in Linux (or, to be more precise, for the non-native
themes painted by Tk) - there is just the visual feedback missing. The
bug for X11 has been discussed before:


http://sourceforge.net/tracker/index.php?func=detail&aid=3217462&group_id=12997&atid=112997

https://groups.google.com/forum/?fromgroups=#!searchin/comp.lang.tcl/tri-state/comp.lang.tcl/Yez7jDxiNQQ/OLTGy8LUwHkJ

Jeff Hobbs showed how it can be easily fixed, but sadly the bug is not
respected:(

Tk & TTk-widgets are NOT entirely interchangable - also in other repsects.
The question is, should the ttk::entry widget also support such an
alternate state for unset variables? IMHO it is right to support unset
linked variables.

> And to increase the confusion completely:
> Test on Windows XP, Tcl8.6b1.2
>
> package require Tk
> pack [checkbutton .c -variable var -tristatevalue 2]
> set var 2
>
> After creation the state is "unchecked", when setting var to the
> tristate value 2 the checkbox is changed to "checked", not tristate!
>


Is it a regression from this bug, maybe?

http://sourceforge.net/tracker/index.php?func=detail&aid=1865898&group_id=12997&atid=112997


Christian

MartinLemburg@Siemens-PLM

unread,
Nov 6, 2012, 3:32:37 AM11/6/12
to
Am Montag, 5. November 2012 09:01:09 UTC+1 schrieb Harald Oehlmann:
> IMHO it is a bug. This should not throw an error. Please file a bug report. Thanks, Harald

IMHO Harald is right ... it's a bug.

Even if to argue if Tk behaves correctly implicitly setting the not existing variable to an empty string ... this is a long known stable behavior and Ttk has to care for such things and must be as close as possible to the Tk behavior!

That's why it is a bug!

Gerhard Reithofer

unread,
Nov 6, 2012, 2:28:32 PM11/6/12
to
Item created successfully. (Artifact 3584830)

Gerhard Reithofer

unread,
Nov 6, 2012, 2:19:03 PM11/6/12
to
Hi Christian,

On Tue, 6 Nov 2012, Christian Gollwitzer wrote:

> Am 05.11.12 19:12, schrieb Gerhard Reithofer:
> > On Sat, 3 Nov 2012, Christian Gollwitzer wrote:
> > > For an entry, this might not be very useful. However, radiobuttons and
> > > checkboxes use unset variables for tri-state information. Unfortunately,
> > > there
> > > is a bug in the X11 versions of Tk that the third state is not displayed
> > > correctly. On Win&Aqua, however, this displays a checkbutton with an
> > > initial "undecided" third state:
> > >
> > > pack [ttk::checkbutton .c -text "Undecided" -variable notinitialized]
> >
> > This is another "problem", isn't it?
> > Ttk checkbox doesn't have -tristate option, Tk has it.
> > Therefore I would call the Win&Aqua behavior as bug.
>
> Definitely not a bug! It is documented in the manual

You are right, the missing option and the search term "tristate" (not
tri-state) made me think that it does not exist.

...

Bye,
Gerhard
0 new messages