encoding:utf8
from Tkinter import * import tkFileDialog as dialog
def save(root, text): data = text.get('0.0', END) filename = dialog.asksaveasfilename( parent = root, filetypes=[('Text', '*.txt')], title ='Save As ...') writer = open(filename, 'w') writer.write(data.encode('utf8')) writer.close()
def quit(root): root.destroy()
window = Tk() text = Text(window) text.pack()
menubar = Menu(window) filemenu = Menu(menubar) filemenu.add_command (label ='save', command = lambda: save (window, text)) filemenu.add_command (label ='end', command = lambda: quit (window))
menubar.add_cascade (label ='file', menu = filemenu) window.config(menu=menubar)
window.mainloop()
'''
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in call
return self.func(*args)
File "menu.py", line 23, in
'''
''' Since it was an error if it was left as it was from the first computer science gui / menu.py Since an error occurred in writer.write (data) I added writer, write (data.encode ('utf8') and data.encode ('utf8'). '''
Recommended Posts