/ Published in: Python

with focus() and center() methods
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
try: from Tkinter import * except: from tkinter import * #py3k class tkWindow(Toplevel): def __init__(self,name,**k): Toplevel.__init__(self,border=4,**k) self.master.withdraw() # hide real tk root self.title(name) def run(self): self.center() self.focus() self.wait_window() def focus(self): self.grab_set() self.focus_set() def center(self): self.update_idletasks() w= self["width"]!=0 and self["width"] or self.winfo_width() h= self["height"]!=0 and self["height"] or self.winfo_height() ws,hs = self.winfo_screenwidth(),self.winfo_screenheight() self.geometry('%dx%d+%d+%d' % (w, h, (ws/2) - (w/2), (hs/2) - (h/2)))
Comments
