Tkinter and wm geometry problem

Brian Moyle bmoyle at mvista.com
Thu Sep 27 21:53:31 EDT 2001


I'm new to Python/Tkinter, so if this is covered somewhere else, please
point me in the right direction.

I want to retain the last-known screen position of an application, so
the next time it starts it appears at the same screen location.

Unfortunately, I seem to be getting inconsistent results when using the
geometry() methods in the Tk class, and I'm not sure how to obtain the
desired results.

Here's the output from a program I wrote that seems to demonstrate the
problem:

[bmoyle at bia tk_geometry_test]$ python tk_wm_test.py
Get: 150x100+304+320
Set: 150x100+300+300
Exit: 150x100+300+300
[bmoyle at bia tk_geometry_test]$ python tk_wm_test.py
Get: 150x100+304+320
Exit: 150x100+304+320
[bmoyle at bia tk_geometry_test]$ 

And here's the program:

[bmoyle at bia tk_geometry_test]$ cat tk_wm_test.py
import sys
from Tkinter import *
class MyApp:
    def __init__(self):
        self.root = Tk()
        frame = Frame(self.root)
        frame.pack()
        self.get = Button(frame, text="Get", command=self.doGet)
        self.get.pack()
        self.set = Button(frame, text="Set", command=self.doSet)
        self.set.pack()
        self.root.protocol('WM_DELETE_WINDOW', self.doExit)
        self.root.geometry("150x100+300+300")
    def doGet(self):
        print "Get: " + self.root.geometry()
    def doSet(self):
        self.root.geometry("150x100+300+300")
        print "Set: " + self.root.geometry()
    def doExit(self):
        print "Exit: " + self.root.geometry()
        sys.exit()
    def Run(self):
        self.root.mainloop()
app=MyApp()
app.Run()

I'm running this from within KDE on a RedHat 7.1 box, with the default
Python rpms (python-1.5.2, tk-8.3.1, tkinter-1.5.2).

Any suggestions?

thanks,

Brian



More information about the Python-list mailing list