macOS Sierra:Python分段错误11
我正在尝试制作一个Python文本编辑器。尝试运行此代码时:macOS Sierra:Python分段错误11,python,macos,tkinter,Python,Macos,Tkinter,我正在尝试制作一个Python文本编辑器。尝试运行此代码时: 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)
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退出,我得到了这个错误
分段错误:11
我使用的是Python2.7.10,它对Python3.5.2也做了同样的事情
我不认为我的代码有问题,但我还是把它放进去了,因为这是可能的。你有什么版本的tcl<代码>打印(root.tk.call('info','patchlevel'))版本
'8.5.7'
或'8.5.9'
对于macosx不稳定。我有8.5。我使用了这些命令local/bin$tclsh%put$tcl\u版本8.5
ok。。。。您能否运行命令print(root.tk.call('info','patchlevel'))
,因为这将为我提供我需要知道的补丁版本。“警告:正在使用的Tcl/tk(8.5.9)版本可能不稳定。有关最新信息,请访问。”