Python 2.7 under Windows: How can we control the position of Tkinter's common dialogs?
Here's what we've discovered:
Questions:
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()
Thank you, Malcolm
For the Windows messagebox you can't. It appears in the center of the screen and that is that. However, the file selection dialog and color chooser are system dialogs that have been given a Tk wrapper so that users see the stock dialogs on this platform. If you set the -parent option then this is passed through to the wrapped windows and it will center itself over your designated toplevel.
In Tk:
toplevel .t
tk_chooseColor -parent .t
How you turn that into Tkinter I leave to someone with some Python experience.
As for centering these, the hwndOwner member of the CHOOSECOLOR structure is always set to the HWND for one of your Tk toplevels. To let it parent against the desktop you'd need to pass NULL there and Tk doesn't let you. You could source the unix version (lib/clrpick.tcl) and show that instead but it would then look weird on a Windows desktop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With