python保存在桌面的文件打不开_python – 在Tkinter中保存文件对话框

我在python中实现了一个基于GUI的文本编辑器.

我已经显示了文本区域,但是当我尝试在Tkinter中使用asksaveasfile方法时,它显示文件已经保存但是当我尝试在桌面编辑器中打开相同的文件时,它会给我一个空白文件.

仅,创建并保存文件.它的内容不是.

我想知道为什么.难道我做错了什么?这是我的代码:

from Tkinter import *

import tkMessageBox

import Tkinter

import tkFileDialog

def donothing():

print "a"

def file_save():

name=asksaveasfile(mode='w',defaultextension=".txt")

text2save=str(text.get(0.0,END))

name.write(text2save)

name.close

root = Tk()

root.geometry("500x500")

menubar=Menu(root)

text=Text(root)

text.pack()

filemenu=Menu(menubar,tearoff=0)

filemenu.add_command(label="New", command=donothing)

filemenu.add_command(label="Open", command=donothing)

filemenu.add_command(label="Save", command=file_save)

filemenu.add_command(label="Save as...", command=donothing)

filemenu.add_command(label="Close", command=donothing)

filemenu.add_separator()

filemenu.add_command(label="Exit", command=root.quit)

menubar.add_cascade(label="File", menu=filemenu)

editmenu=Menu(menubar,tearoff=0)

editmenu.add_command(label="Undo", command=donothing)

editmenu.add_command(label="Copy", command=donothing)

editmenu.add_command(label="Paste", command=donothing)

menubar.add_cascade(label="Edit", menu=editmenu)

helpmenu=Menu(menubar,tearoff=0)

helpmenu.add_command(label="Help",command=donothing)

menubar.add_cascade(label="Help",menu=helpmenu)

root.config(menu=menubar)

root.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值