I am trying to make a Python text editor. When trying to run this code:
from Tkinter import *
from tkFileDialog import *
filename = None
def newFile():
global filename
filename = "Untitled"
text.delete(0.0, END)
def saveFile():
global filename
t = text.get(0.0, end)
f = open(filename, 'w')
f.write(t)
f.close()
def saveAs():
f = asksaveasfile(mode='w', defaultextension='.txt')
t = text.get(0.0, END)
try:
f.write(t.rstrip())
except:
showerror(title="Oops!", message="Unable to save file...")
def openFile():
f = askopenfile(mode='r')
t = f.read()
text.delete(0.0, END)
text.insert(0.0, t)
root = Tk()
root.title("TextEditor")
root.minsize(width=400, height=400)
root.maxsize(width=400, height=400)
text = Text(root, width=400, height=400)
text.pack()
menubar = Menu(root)
filemenu = Menu(menubar)
filemenu.add_command(label="New", command=newFile)
filemenu.add_command(label="Open", command=openFile)
filemenu.add_command(label="Save", command=saveFile)
filemenu.add_command(label="Save As", command=saveAs)
filemenu.add_separator()
filemenu.add_command(label="Quit", command=root.quit)
menubar.add_cascade(label="File", menu=menubar)
root.config(menu=menubar)
root.mainloop()
Python quits and I get this error
Segmentation fault: 11
I am on Python 2.7.10 and it does the same thing with Python 3.5.2
I don't think my code is the problem, but I put it in anyway because it's a possibility.
print(root.tk.call('info', 'patchlevel'))
versions'8.5.7'
or'8.5.9'
are unstable for macosx. – Tadhg McDonald-Jensen Dec 24 '16 at 19:56local/bin $ tclsh % puts $tcl_version 8.5
– Jordan Baron Dec 24 '16 at 19:59print(root.tk.call('info', 'patchlevel'))
since that will give me the patch version which is what I need to know. – Tadhg McDonald-Jensen Dec 24 '16 at 20:01