Re: How to center tkDialog

Vasilis Vlachoudis <[email protected]> Tue, 22 Feb 2022 09:39:32 +0000
Newsgroups gmane.comp.python.tkinter
Message-ID <[email protected]>
--===============2584986361184223170==
Content-Language: en-US
Content-Type: multipart/alternative;
	boundary="_000_0BC70B5D93E054469872FFD0FE07220E033860E8C2CERNXCHG53cer_"

--_000_0BC70B5D93E054469872FFD0FE07220E033860E8C2CERNXCHG53cer_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 =3D tk.Tk()
t2 =3D tk.Toplevel(root)
t2.transient(root)
tk.Label(t2, text=3D'This is a transient window of root').pack(padx=3D10, p=
ady=3D10)
# 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=3Dcern.ch=
@python.org] on behalf of Vasilis Vlachoudis [[email protected]]
Sent: Tuesday, February 22, 2022 09:42
To: [email protected]
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=3D

any ideas on how to center it?

Vasilis

--_000_0BC70B5D93E054469872FFD0FE07220E033860E8C2CERNXCHG53cer_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html dir=3D"ltr">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" id=3D"owaParaStyle"></style>
</head>
<body fpstyle=3D"1" ocsi=3D"0">
<div style=3D"direction: ltr;font-family: Tahoma;color: #000000;font-size: =
10pt;">For some reason the &quot;transient()&quot; is not enough to center =
the window.
<div>I was looking the code of the msgbox.tcl (Messagebox)</div>
<div>and there is a command</div>
<div><span style=3D"font-size: 13.3333px;">::tk::PlaceWindow $w widget $dat=
a(-parent)</span></div>
<div>Using this command it centers the dialog e.g.</div>
<div><br>
</div>
<div>
<div><span style=3D"font-size: 13.3333px;"><span style=3D"white-space:pre">=
</span>root =3D tk.Tk()</span></div>
<div><span style=3D"font-size: 13.3333px;"><span style=3D"white-space:pre">=
</span>t2 =3D tk.Toplevel(root)</span></div>
<div><span style=3D"font-size: 13.3333px;"><span style=3D"white-space:pre">=
</span>t2.transient(root)</span></div>
<div><span style=3D"font-size: 13.3333px;"><span style=3D"white-space:pre">=
</span>tk.Label(t2, text=3D'This is a transient window of root').pack(padx=
=3D10, pady=3D10)</span></div>
<div><span style=3D"font-size: 13.3333px;"><span style=3D"white-space:pre">=
</span># root.tk.call(&quot;::tk::PlaceWindow&quot;, t2, &quot;widget&quot;=
, root)</span></div>
<div><span style=3D"font-size: 13.3333px;"><span style=3D"white-space:pre">=
</span>root.mainloop()</span></div>
</div>
<div><br>
</div>
<div>as is the dialog is centered wrt the screen,</div>
<div>when you uncomment the PlaceWindow command it is properly placed on to=
p of the root window</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div style=3D"font-family: Times New Roman; color: #000000; font-size: 16px=
">
<hr tabindex=3D"-1">
<div id=3D"divRpF978237" style=3D"direction: ltr;"><font face=3D"Tahoma" si=
ze=3D"2" color=3D"#000000"><b>From:</b> Tkinter-discuss [tkinter-discuss-bo=
unces&#43;[email protected]] on behalf of Vasilis Vla=
choudis [[email protected]]<br>
<b>Sent:</b> Tuesday, February 22, 2022 09:42<br>
<b>To:</b> [email protected]<br>
<b>Subject:</b> [Tkinter-discuss] How to center tkDialog<br>
</font><br>
</div>
<div></div>
<div>
<div style=3D"direction:ltr; font-family:Tahoma; color:#000000; font-size:1=
0pt">
<div>Hi all,</div>
when using the tkDialogs.Dialog(), it always appears centered in the screen
<div>and not as on-top/transient of the master window.</div>
<div>In contrast with the other dialogs it doesn't seem to respect the</div=
>
<div>parent=3D</div>
<div><br>
</div>
<div>any ideas on how to center it?</div>
<div><br>
</div>
<div>Vasilis</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

--_000_0BC70B5D93E054469872FFD0FE07220E033860E8C2CERNXCHG53cer_--

--===============2584986361184223170==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tkinter-discuss mailing list
[email protected]
https://mail.python.org/mailman/listinfo/tkinter-discuss

--===============2584986361184223170==--