Python 2.7 / Windows: how to control the position of common Tkinter dialogs?

Python 2.7 on Windows: how can we control the position of common Tkinter dialogs?

Here is what we found:

  • Some common dialogs always open relative to their parent window.
  • Certain common dialogs always open in the center of the user's desktop
  • All common dialogs seem to ignore the optional parent = parameter

Questions:

  • How to make a dialog box open its parent window?
  • How to make a dialog box open in the center of the desktop?

Background:

import tkColorChooser as colorchooser import tkFileDialog as filedialog import tkMessageBox as messagebox ; # always open up relative to parent windows fileOpen = filedialog.askopenfilename() fileOpens = filedialog.askopenfilenames() fileSaveAs = filedialog.asksaveasfilename() color = colorchooser.askcolor() ; # always open up centered on desktop folderOpen = filedialog.askdirectory() messagebox.askquestion() 

Thanks Malcolm

+6
python windows tkinter ttk
source share
1 answer

For windows message box you cannot. It appears in the center of the screen, and that’s it. However, the file selection dialog and the color selection are system dialogs that were provided with the Tk chip so that users can see the stock dialogs on this platform. If you set the -parent option, it will be passed to the wrapped windows and it will be centered at your assigned level.

In Tk:

 toplevel .t tk_chooseColor -parent .t 

As you turn this into Tkinter, I am leaving for someone with Python experience.

As for their centering, the hwndOwner member of the CHOOSECOLOR structure is always set to HWND for one of your Tk levels. To allow it to be born against the desktop, you need to pass NULL, and Tk does not allow you. You can specify the unix version (lib / clrpick.tcl) and show it, but instead it will look strange on the Windows desktop.

+1
source share

All Articles