Z
Zora Honey
I'm trying to get a Tkinter window to open up in the same place on my
screen that I left it the last time I quit the application. To do this,
I simply write the position to a file at "exit" and at startup, I read
the file. Simple enough, but it doesn't work. Oftentimes it's "close",
but over several iterations, the window will wander all over the screen.
In the output below, you can see that the x offset is "off" by +4 each
iteration. Until I move the window. Then x and y are off for one
iteration. Then back to just x.
Anybody know what the heck is going on here?
Thanks,
Zora
------Output-------
before=, 1x1+0+0
after= 200x200+16+795
out= +16+795
before=, 1x1+0+0
after= 200x200+20+795
out= +20+795
before=, 1x1+0+0
after= 200x200+24+795
out= +24+795
##move window##
before=, 1x1+0+0
after= 200x200+28+795
out= +1045+856
before=, 1x1+0+0
after= 200x200+1049+795
out= +1049+795
before=, 1x1+0+0
after= 200x200+1053+795
out= +1053+795
before=, 1x1+0+0
after= 200x200+1057+795
-------Code--------
from Tkinter import *
if __name__=="__main__":
def die():
root.update_idletasks()
newGeometry='+%d+%d' % (root.winfo_x(), root.winfo_y())
print "out=", newGeometry
if (newGeometry!=geometryConfig):
config=open("alarm.config", 'w')
config.write(newGeometry+'\n')
sys.exit(0)
root=Tk()
try:
config=open("alarm.config")
geometryConfig=config.readline()[:-1]
config.close()
print "in=", geometryConfig
print "before=,", root.geometry(newGeometry=None)
root.geometry(newGeometry=geometryConfig)
root.update()
print "after=", root.geometry(newGeometry=None)
except :
pass
exitb=Button(root, text="Exit", command=die)
exitb.pack(side=LEFT)
root.mainloop()
screen that I left it the last time I quit the application. To do this,
I simply write the position to a file at "exit" and at startup, I read
the file. Simple enough, but it doesn't work. Oftentimes it's "close",
but over several iterations, the window will wander all over the screen.
In the output below, you can see that the x offset is "off" by +4 each
iteration. Until I move the window. Then x and y are off for one
iteration. Then back to just x.
Anybody know what the heck is going on here?
Thanks,
Zora
------Output-------
in= +12+795> python alarmsend.py
before=, 1x1+0+0
after= 200x200+16+795
out= +16+795
in= +16+795> python alarmsend.py
before=, 1x1+0+0
after= 200x200+20+795
out= +20+795
in= +20+795> python alarmsend.py
before=, 1x1+0+0
after= 200x200+24+795
out= +24+795
##move window##
in= +24+795> python alarmsend.py
before=, 1x1+0+0
after= 200x200+28+795
out= +1045+856
in= +1045+856> python alarmsend.py
before=, 1x1+0+0
after= 200x200+1049+795
out= +1049+795
in= +1049+795> python alarmsend.py
before=, 1x1+0+0
after= 200x200+1053+795
out= +1053+795
in= +1053+795> python alarmsend.py
before=, 1x1+0+0
after= 200x200+1057+795
-------Code--------
from Tkinter import *
if __name__=="__main__":
def die():
root.update_idletasks()
newGeometry='+%d+%d' % (root.winfo_x(), root.winfo_y())
print "out=", newGeometry
if (newGeometry!=geometryConfig):
config=open("alarm.config", 'w')
config.write(newGeometry+'\n')
sys.exit(0)
root=Tk()
try:
config=open("alarm.config")
geometryConfig=config.readline()[:-1]
config.close()
print "in=", geometryConfig
print "before=,", root.geometry(newGeometry=None)
root.geometry(newGeometry=geometryConfig)
root.update()
print "after=", root.geometry(newGeometry=None)
except :
pass
exitb=Button(root, text="Exit", command=die)
exitb.pack(side=LEFT)
root.mainloop()