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 = 'Speichern unter ...') 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 (Fenster, Text)) filemenu.add_command (label = 'end', command = lambda: quit (Fenster))
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
'''
''' Da es ein Fehler war, wenn es so belassen wurde, wie es von der ersten Informatik gui / menu.py war Ich habe einen Fehler in writer.write (Daten) erhalten Ich habe Writer, Write (data.encode ('utf8') und data.encode ('utf8') hinzugefügt. '''
Recommended Posts