1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import Tkinter
import ConfigParser
import sys
def quitApp():
ini.set('main_window', 'x', root.winfo_rootx() - 4) # if somebody can explane these offsets...
ini.set('main_window', 'y', root.winfo_rooty() - 23) # because I can't! :o)
ini.set('main_window', 'width', root.winfo_width())
ini.set('main_window', 'height', root.winfo_height())
ini.write(open(ininame, 'w'))
root.quit()
ininame = '%s.ini'%sys.argv[0]
ini = ConfigParser.ConfigParser()
ini.read(ininame)
if not len(ini.sections()):
print "no inifile"
ini.add_section('main_window')
geostr = "640x480+0+0"
else:
print "inifile found"
width = ini.getint('main_window', 'width')
height = ini.getint('main_window', 'height')
x = ini.getint('main_window', 'x')
y = ini.getint('main_window', 'y')
geostr = "%ix%i+%i+%i"%(width, height, x, y)
root = Tkinter.Tk()
print geostr
root.geometry(geostr)
root.protocol('WM_DELETE_WINDOW', quitApp)
root.mainloop() |
Partager