Save text from Tk widget?
Steve
smnordby at yahoo.com
Sun Oct 22 19:38:06 EDT 2000
I have a function inside my main class to open a file in a ScrolledText
widget.
The default Windoze key bindings work for simple text editing, so I
added
a save function, but I declare a global variable to get the widget
contents to the save function. There must be a better way?
def viewDict(self):
new = Toplevel()
global zd
zd = ScrolledText(new, height = 30, width = 70)
zd.pack(fill=BOTH, expand=YES)
zd.insert('0.0', open('c:/mytools/mydict.py', 'r').read())
Button(new, text='Save', fg='red', command=self.saveDict).pack()
def saveDict(self):
contents = zd.get(1.0, END)
output = open('c:/mytools/mydict.py', 'w')
output.write(contents)
output.close()
More information about the Python-list
mailing list