From: schliep at octopussy.mi.uni-koeln.de (Alexander Schliep)
Date: 07 Apr 1999 23:44:39 +0200
Subject: Tkinter and centering
References: <370B88CF.993D8847@yahoo.com>
	<370BC217.FFF53A35@vision.arc.nasa.gov>
Message-ID: <tq9u2us14xk.fsf@Octopussy.MI.Uni-Koeln.DE>
Content-Length: 1971
X-UID: 1406                                                  

Chad Netzer <chad at vision.arc.nasa.gov> writes:

> Well, I don't know if you can ever get the window width and height without
> first mapping it (displaying).  One option is to open it completely off the

I found a solution in Effective Tcl/Tk. You have to call update_idletasks()
which forces geometry calculations first and then you can move the window.

Here is some sample code I wrote for a splash screen. 

Alexander




class SplashScreen(Toplevel):
    """ 
        Subclass and override 'CreateWidgets()'
 
        In constructor of main window/application call      
        - S = SplashScreen(main=self)        (if caller is Toplevel) 
        - S = SplashScreen(main=self.master) (if caller is Frame) 
        - S.Destroy()  after you are done creating your widgets etc.
    """
 
    def __init__(self, master=None):
        Toplevel.__init__(self, master, relief=RAISED, borderwidth=5)
        self.main = master
        if self.main.master != None: # Why ?
            self.main.master.withdraw()
        self.main.withdraw()
        self.overrideredirect(1)
        self.CreateWidgets()
        self.after_idle(self.CenterOnScreen)
        self.update()
 
    def CenterOnScreen(self):
        self.update_idletasks()
        xmax = self.winfo_screenwidth()
        ymax = self.winfo_screenheight()
        x0 = (xmax - self.winfo_reqwidth()) / 2
        y0 = (ymax - self.winfo_reqheight()) / 2
        self.geometry("+%d+%d" % (x0, y0))
    
    def CreateWidgets(self):
	# Need to fill in here	
                
    def Destroy(self):
        self.main.update()
        self.main.deiconify()
        self.withdraw()
 



-- 
Alexander Schliep                    schliep at zpr.uni-koeln.de
ZPR/ZAIK                             Tel: +49-221-470-6011 (w)
University of Cologne                FAX: +49-221-470-5160
Weyertal 80                          http://www.zpr.uni-koeln.de/~schliep
50931 Cologne, Germany               Tel: +49-231-143083 (h)




