Save text from Tk widget?
Steve
smnordby at yahoo.com
Mon Oct 23 08:05:03 EDT 2000
Steve Holden wrote:
>
> Steve wrote:
> >
> > 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?
> >
>
> Make zd an instance variable instead: this even allows you to have
> multiple instances which won't interfere with each other.
>
> def viewDict(self):
> new = Toplevel()
> self.zd = ScrolledText(new, height = 30, width = 70)
> self.zd.pack(fill=BOTH, expand=YES)
> self.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 = self.zd.get(1.0, END)
> output = open('c:/mytools/mydict.py', 'w')
> output.write(contents)
> output.close()
>
Thanks Steve! I should have known to allow my self to introduce my
self!
-Steve-
More information about the Python-list
mailing list