Tk Source Code

View Ticket
Login
Ticket UUID: 220896
Title: focus shifts to wrong window after using tk_ built in dialog
Type: Bug Version: obsolete: 8.3
Submitter: welch Created on: 2000-11-01 01:32:42
Subsystem: 33. Generic Dialog Support Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2004-09-11 01:31:07
Resolution: Invalid Closed By: hobbs
    Closed on: 2004-09-10 18:31:07
Description:
OriginalBugID: 4254 Bug
Version: 8.3
SubmitDate: '2000-02-28'
LastModified: '2000-03-01'
Severity: MED
Status: UnAssn
Submitter: angie
ChangedBy: hobbs
OS: Windows NT
OSVersion:  4.0sp5


Tk 8.3.0 Bug

ReproducibleScript:
# focuslostbug.tcl
wm title . "New focus"
toplevel .t
wm title .t "Original focus"
update
button .t.b -text "Press me!" -command focusbug
pack .t.b 
focus .t
proc focusbug {} {
    tk_messageBox  -icon    question  -type    yesno  -default no  -message "Please press a button!  Notice how focus shifts"  -title  "Focus bug"
}

ObservedBehavior:
When using tk_messageBox, or similar dialogs (on WinNT at least), the focus is not reset correctly when the dialog is dismissed.  This happens even though the dialog tries to do 'set oldFocus [focus] .... catch {focus $oldFocus}' internally.

The script attached demonstrates this problem.  There are two windows, with the focus on one containing a button.  Pressing the button brings up a simple dialog, but when that dialog is dismissed the focus is now on the window without the button (the root '.' window).

DesiredBehavior:
Focus should remain where it was before.

Patch:
Using 'focus -force' can solve the problem, but I don't think it's a good solution (at least the focus man page suggests not to use -force).

Comments:
    Tk 8.2.3 and 8.3.0 show the bug on WinNT.

Posted To comp.lang.tcl: Posted Successfully
User Comments: hobbs added on 2004-09-11 01:31:07:
Logged In: YES 
user_id=72656

The bug is in the script and not using the -parent arg,
which means default to -parent ., where focus will return.