Tk Source Code

View Ticket
Login
2026-10-14
16:36 • Closed ticket [3414693f]: tk_dialog: (mis)placement plus 7 other changes artifact: a338eb01 user: jan.nijtmans
16:32
Fix [3414693]: tk_dialog is centered over its parent window check-in: 636dfb8f user: jan.nijtmans tags: core-8-6-branch
15:19
Fix [3414693]: tk_dialog is centered over its parent window check-in: 0f1dda77 user: jan.nijtmans tags: core-9-0-branch
15:16
Fix [3414693]: tk_dialog is centered over its parent window check-in: 7607b798 user: jan.nijtmans tags: trunk, main
2026-10-01
18:40 • Ticket [3414693f] tk_dialog: (mis)placement status still Open with 3 other changes artifact: 00c7351b user: serhiy.storchaka
18:38
Fix [3414693fff]: tk_dialog is centered over its parent window, like tk_messageBox and other Tk dialogs, not on the screen.

Patch by fvogel. closed check-in: e34eec51 user: serhiy.storchaka tags: tk-dialog-over-parent

2023-01-22
21:18 • Ticket [3414693f] tk_dialog: (mis)placement status still Open with 3 other changes artifact: 6590e91d user: fvogel
21:16 • Ticket [3414693f]: 6 changes artifact: 203b57c8 user: fvogel
2011-09-27
20:04 • New ticket [3414693f]. artifact: ed1b49de user: zbigniew_b

Ticket UUID: 3414693
Title: tk_dialog: (mis)placement
Type: Bug Version: None
Submitter: zbigniew_b Created on: 2011-09-27 20:04:49
Subsystem: 35. [tk_dialog] Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-14 16:36:21
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2026-10-14 16:36:21
Description:
tk_dialog is centered in relation to "physical" screen - and, unfortunately, not to "root window", like e.g. tk_messageBox is.
User Comments: jan.nijtmans added on 2026-10-14 16:36:21:

Fixed in [7607b7988e21530d|trunk], core-9-0-branch and core-8-6-branch

Many thanks!


serhiy.storchaka added on 2026-10-01 18:40:44:

All other Tk dialogs (tk_messageBox, tk_chooseColor, tk_chooseDirectory, tk_getOpenFile, the font chooser) are centered over their parent, and tkinter's simpledialog, which reimplements tk_dialog, does the same.

Proposed fix in branch [tk-dialog-over-parent]: fvogel's patch, plus test dialog-2.4. The parent is the parent of the dialog window (usually "."). The Motif-style placement can still be obtained: if the parent is not mapped (e.g. a withdrawn "."), the dialog is centered on the screen as before.


fvogel added on 2023-01-22 21:18:13:

Oh, and here is the test case:

package require Tk
tk_dialog .d hello "my test" questhead 0 OK Cancel


fvogel added on 2023-01-22 21:16:56:

I think you are talking about platforms like Linux that do not instantiate a native dialog but a Tk_made one.

The following patch makes tk_dialog behave as tk_messageBox, fontchooser, tk_chooseDirectory, tk_chooseColor:

Index: library/dialog.tcl
==================================================================
--- library/dialog.tcl
+++ library/dialog.tcl
@@ -141,11 +141,11 @@

     # 6. Withdraw the window, then update all the geometry information
     # so we know how big it wants to be, then center the window in the
     # display (Motif style) and de-iconify it.

-    ::tk::PlaceWindow $w
+    ::tk::PlaceWindow $w widget [winfo parent $w]
     tkwait visibility $w

     # 7. Set a grab and claim the focus too.

     if {$default >= 0} {

However I'm a little bit hesitating to apply this patch to Tk because it looks like the current behavior is intentional. The comment in the above snippet says the window will be centered in the display since this is Motif-style. That said, we can probably make this change since Motif is long dead.