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

Floating window freezes entry text

65 views
Skip to first unread message

Alexandru

unread,
Apr 18, 2016, 10:57:41 PM4/18/16
to
Hi,

I have an entry and a button that creates a floating window, that contains only one close button. My OS is Windows.

In order to reproduce the problem, please run and test the code below like this:

1. Try to select something in the entry -> It will work
2. Press on the button to show the floating window -> A new toplevel will appear
3. Try to select something in the entry -> It will still work
4. Close the floating window and try to select again -> It won't work
5. Minimize and maximize the main toplevel and try to select again -> It will work again

Is there a way to make the entry selectable after the floating window is closed?

Actually the text is selected but the selection is not visible...

Thanks
Alexandru

#-----------------------------------
# Run this code:
#-----------------------------------
set text "This text cannot be selected after the floating window is closed"
pack [ttk::entry .e -textvariable ::text] -expand 1 -fill x
pack [ttk::button .b -text "Show floating window" -command Show] -expand 1 -fill x

proc Show {} {
# Make a floating window, always on top
WindowFloating .tooltip 1
# Add entry widget
pack [ttk::button .tooltip.close -text "Close" -command "destroy .tooltip" -text close]
wm geometry .tooltip +300+300
}

# Make a floating window
proc WindowFloating {w {ontop 0}} {
# Toplevel window
destroy $w
toplevel $w -bd 1 -bg white -relief raised
# Get screen dimensions
set scrh [winfo screenheight [winfo parent $w]] ;# 1) flashing window fix
set scrw [winfo screenwidth [winfo parent $w]] ;# 1) flashing window fix
wm geometry $w +$scrh+$scrw ;# 1) flashing window fix
wm overrideredirect $w 1
# Dont set window always on top! This freezes all entries so that they can't take focus anymore
if {$ontop} {
wm transient $w .
}
raise $w
focus $w
return $w
}
#-----------------------------------

Brad Lanam

unread,
Apr 18, 2016, 11:06:23 PM4/18/16
to
Confirmed not working as described on win7-64.
Works on Linux.

Brad Lanam

unread,
Apr 18, 2016, 11:08:37 PM4/18/16
to
On Monday, April 18, 2016 at 8:06:23 PM UTC-7, Brad Lanam wrote:
> Confirmed not working as described on win7-64.
> Works on Linux.

Commenting out the overrideredirect allows it to work, but obviously
that's not what is wanted.

Alexandru

unread,
Apr 18, 2016, 11:24:09 PM4/18/16
to
Yes, overrideredirect is necessary...

I was wondering, why minimizing and restoring the main toplevel makes it work again? Can this be emulated without really minimizing the window?

Brad Lanam

unread,
Apr 19, 2016, 5:17:49 AM4/19/16
to
On Monday, April 18, 2016 at 8:24:09 PM UTC-7, Alexandru wrote:
> I was wondering, why minimizing and restoring the main toplevel makes it work again? Can this be emulated without really minimizing the window?

Hmmm...I didn't try that.
wm withdraw .
wm deiconify .
Yes, that works, but you get a flash of the window.
It's a workaround.

Are you going to open a ticket for this?

Rich

unread,
Apr 19, 2016, 6:01:45 AM4/19/16
to
Alexandru <alexandr...@meshparts.de> wrote:
> Hi,

> I have an entry and a button that creates a floating window, that
> contains only one close button. My OS is Windows.

> In order to reproduce the problem, please run and test the code below
> like this:

> 1. Try to select something in the entry -> It will work
> 2. Press on the button to show the floating window -> A new toplevel
> will appear
> 3. Try to select something in the entry -> It will still work
> 4. Close the floating window and try to select again -> It won't work

On Linux, after this step the text in the entry is fully selectable.

> 5. Minimize and maximize the main toplevel and try to select again ->
> It will work again

No need, the entry never stopped being selectable.

> Is there a way to make the entry selectable after the floating window
> is closed?

Uninstall Windows -- Install Linux :)

In all seriousness, you seem to be tickling some kind of Windows
weirdness. Whether it is a weirdness related to Tk's windows
interface, or a core windows weirdness I do not know.

Alexandru

unread,
Apr 19, 2016, 7:08:42 AM4/19/16
to
Thanks. It works but I can't live with the window flashing around like that.

I once tried to understand how the tickets are working but frankly I can't really get a hint at that.

Alexandru

unread,
Apr 19, 2016, 7:10:39 AM4/19/16
to
Am Dienstag, 19. April 2016 12:01:45 UTC+2 schrieb Rich:
Yeah, and I though Tcl/Tk is multiplatform... Damn I was wrong! I'll go right away an install Linux.

Alexandru

unread,
Apr 19, 2016, 7:22:38 AM4/19/16
to
I have found an workaround:

Instead of destroying the floating window, I use "wm withdraw".

Thanks for the tips!

Regards
Alexandru

Rich

unread,
Apr 19, 2016, 7:31:39 AM4/19/16
to
That was tounge-in-cheek. You did ask "is there a way" (a very broad,
all encompassing question). There _is_ a way (at least one), just
maybe not a way that is reasonable for where you want to go.

In any case, you seem to have found a bug, so as someone else in the
thread suggested (Brad maybe?), file a bug report on the tracker.
Whatever is causing it is not likely to be fixed unless a bug report
gets filed. You've got a great bug report already simply because you
have a short script test case that triggers the bug. All you need to
do now is file it.

Alternately, as someone else reported, not making that toplevel
override redirect prevented the bug, so could you live with that
floating toplevel not being overrideredirect?

Also have you tried using the "wm transient" state. That might help
avoid this particular bug. However as I'm on Linux, I can't test that
change to see what effect it might have on windows.

Alexandru

unread,
Apr 19, 2016, 7:49:22 AM4/19/16
to
Okay Rich, I have created a new ticket: http://core.tcl.tk/tk/tktview/aa73806f6c4c3dd367feb1faf1f84d96895d0ff2

The "wm transient" state is exactly what is causing the problem as stated in the code. Without it, there is no problem. But I cannot omit this option.

Regards
Alexandru

Brad Lanam

unread,
Apr 19, 2016, 7:53:44 AM4/19/16
to
> Alexandru <alexandru...> wrote:
> > Yeah, and I though Tcl/Tk is multiplatform... Damn I was wrong! I'll
> > go right away an install Linux.

Wait until you try porting to Mac OS X with the aqua theme.
I've a good bit of if == Darwin, if == aqua stuff.

On Tuesday, April 19, 2016 at 4:31:39 AM UTC-7, Rich wrote:
> Also have you tried using the "wm transient" state. That might help
> avoid this particular bug. However as I'm on Linux, I can't test that
> change to see what effect it might have on windows.

Install a VM. Makes cross platform testing much easier.

Rich

unread,
Apr 19, 2016, 8:34:33 AM4/19/16
to
Ah, I didn't look at the code close enough. You've got this:

wm overrideredirect $w 1
# Dont set window always on top! This freezes all entries so that they can't take focus anymore
if {$ontop} {
wm transient $w .

Which wne you set the boolean parameter to your proc, you set *both*
overrideredirect *and* transient.

That may be the the cause. Setting both states simultaneously.
Overrideredirect means the window manager ignores the window entirely.
Transient means it manages it, but with a different purpose than normal
windows.

The wondow can't be _ignored_ and _managed_ simultaneously.

Try something more like this:

if {$ontop} { wm transient $w . } else { wm overrideredirect $w 1 }

and see what happens.

Alexandru

unread,
Apr 19, 2016, 9:01:50 AM4/19/16
to
That might work, but actually I need both transient and overrideredirect if I want to have a tooltip-like window always on top.

Harald Oehlmann

unread,
Apr 19, 2016, 10:03:27 AM4/19/16
to
Am 19.04.2016 um 15:01 schrieb Alexandru:
> That might work, but actually I need both transient and overrideredirect if I want to have a tooltip-like window always on top.
>

Maybee, again, the BWidget tooltip code in dynhelp.tcl may help you:

toplevel $_top -relief flat \
-bg [Widget::getoption $_top -topbackground] \
-bd [Widget::getoption $_top -borderwidth] \
-screen [winfo screen $w]

wm withdraw $_top
if { $Widget::_aqua } {
::tk::unsupported::MacWindowStyle style $_top help none
} else {
wm overrideredirect $_top 1
}

catch { wm attributes $_top -topmost 1 }

label $_top.label -text $string \
-relief flat -bd 0 -highlightthickness 0 \
-padx [Widget::getoption $_top -padx] \
-pady [Widget::getoption $_top -pady] \
-foreground [Widget::getoption $_top -foreground] \
-background [Widget::getoption $_top -background] \
-font [Widget::getoption $_top -font] \
-justify [Widget::getoption $_top -justify]


pack $_top.label -side left
update idletasks

if {![winfo exists $_top]} {return}

set scrwidth [winfo vrootwidth .]
set scrheight [winfo vrootheight .]
set width [winfo reqwidth $_top]
set height [winfo reqheight $_top]

# On windows multi screen configurations, the virtual screen may
start
# at negative positions.
set scrrootx [winfo vrootx .]
set scrrooty [winfo vrooty .]

# Increment the required size by the deplacement from the passed
point
incr width 8
incr height 12

# Put at the right border if going over it
if { $x+$width > $scrrootx+$scrwidth } {
set x [expr {$scrwidth + $scrrootx - $width + 8}]
} else {
incr x 8
}
# Put above widget if below is no space
if { $y+$height > $scrrooty+$scrheight } {
set y [expr {$y - $height}]
} else {
incr y 12
}

wm geometry $_top "+$x+$y"
update idletasks

if {![winfo exists $_top]} { return }
wm deiconify $_top
raise $_top
# Sometimes the tooltip does not occur under
# gnome/metacity on ubuntu.
after 5;
}


--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Rich

unread,
Apr 19, 2016, 10:22:40 AM4/19/16
to
Except for the fact that "overrideredirect" means "completely
unmanaged" by the window manager and "transient" means "managed" by the
window manager. A window can't be simultaneously "managed" and
"unmanaged".

If you want it "on top" you should use the -topmost option to wm
attributes.

Alexandru

unread,
Apr 19, 2016, 3:57:11 PM4/19/16
to
The -topmost option does not work the same. The window must remain ontop, even if the focus changes or if I click on the main toplevel.

Rich

unread,
Apr 19, 2016, 6:05:43 PM4/19/16
to
If you are poping something up inside another Tk window, have you tried
the [place] geometry manager for the "pop-up" item itself? You'll be
able to 'keep it on top' (of the main window) without having to resort
to wm options/hacks that (as you've now found) do not always work the
same way cross platform.

Another option is to bind to a Visibility event and [raise] the window
any time the Visibility changes.

0 new messages