Hi all, when using the tkDialogs.Dialog(), it always appears centered in the screen and not as on-top/transient of the master window. In contrast with the other dialogs it doesn't seem to respect the parent= any ideas on how to center it? Vasilis
For some reason the "transient()" is not enough to center the window. I was looking the code of the msgbox.tcl (Messagebox) and there is a command ::tk::PlaceWindow $w widget $data(-parent) Using this command it centers the dialog e.g. root = tk.Tk() t2 = tk.Toplevel(root) t2.transient(root) tk.Label(t2, text='This is a transient window of root').pack(padx=10, pady=10) # root.tk.call("::tk::PlaceWindow", t2, "widget", root) root.mainloop() as is the dialog is centered wrt the screen, when you uncomment the PlaceWindow command it is properly placed on top of the root window ________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch@python.org] on behalf of Vasilis Vlachoudis [Vasilis.Vlachoudis@cern.ch] Sent: Tuesday, February 22, 2022 09:42 To: tkinter-discuss@python.org Subject: [Tkinter-discuss] How to center tkDialog Hi all, when using the tkDialogs.Dialog(), it always appears centered in the screen and not as on-top/transient of the master window. In contrast with the other dialogs it doesn't seem to respect the parent= any ideas on how to center it? Vasilis
In a rather large program I have this code: self.TextWidget.focus_set() print("type(self.TextWidget)=%s"%type(self.TextWidget)) print('Focus_get()=%s'%self.focus_get()) The goal is to have TextWidget get the focus. Usually it does, but there is one particular circumstance when it does not get the focus. The "print" lines I added for debugging. The output from the print functions is: type(self.TextWidget)=<class 'rpWidgets.ColorizedText'> Focus_get()=None TextWidget is an instance of rpWidgets.ColorizedText which is created thus: class ColorizedText(tkinter.Text): which is to say, it's just a tkinter.Text to which I've added methods. I've tried creating a minimum example without success. My questions is: how is it possible for TextWidget to NOT have the focus immediately after a call to focus_set? Changing focus_set to focus_force makes no difference. Invoking update_idletasks() after the focus_set makes no difference. The TextWidget in question is visible on the screen, and pressing Tab a couple of times does get it the focus. Having spent some hours chasing this I'm a tad frustrated, but quite open to suggestions about what to look for. Cheers Cam Farnell
To answer my own question: the focus was being given to another widget after the code in question had executed. That said, I still don't understand why focus_set followed by update_idletasks followed by focus_get would return None, but tkinter something works in strange and mysterious ways. Cheers Cam On 2024-01-10 08:44, Cam Farnell wrote:
In a rather large program I have this code:
self.TextWidget.focus_set() print("type(self.TextWidget)=%s"%type(self.TextWidget)) print('Focus_get()=%s'%self.focus_get())
The goal is to have TextWidget get the focus. Usually it does, but there is one particular circumstance when it does not get the focus. The "print" lines I added for debugging.
The output from the print functions is:
type(self.TextWidget)=<class 'rpWidgets.ColorizedText'> Focus_get()=None
TextWidget is an instance of rpWidgets.ColorizedText which is created thus:
class ColorizedText(tkinter.Text):
which is to say, it's just a tkinter.Text to which I've added methods.
I've tried creating a minimum example without success.
My questions is: how is it possible for TextWidget to NOT have the focus immediately after a call to focus_set?
Changing focus_set to focus_force makes no difference.
Invoking update_idletasks() after the focus_set makes no difference.
The TextWidget in question is visible on the screen, and pressing Tab a couple of times does get it the focus.
Having spent some hours chasing this I'm a tad frustrated, but quite open to suggestions about what to look for.
Cheers
Cam Farnell
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
Hi, On Wed, 10 Jan 2024 16:33:46 -0400 Cam Farnell <msa01@bitflipper.ca> wrote:
To answer my own question: the focus was being given to another widget after the code in question had executed.
That said, I still don't understand why focus_set followed by update_idletasks followed by focus_get would return None, but tkinter something works in strange and mysterious ways.
I can only guess here, have you tried calling update_idletasks() (or even update()) *before* calling focus_set() ? Best regards, Michael
participants (3)
-
Cam Farnell -
Michael Lange -
Vasilis Vlachoudis