Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
macOS Sierra:Python分段错误11_Python_Macos_Tkinter - Fatal编程技术网

macOS Sierra:Python分段错误11

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)

我正在尝试制作一个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)
    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)版本可能不稳定。有关最新信息,请访问。”