|
10鱼币
题目做了一半,代码如下
- import easygui as eg
- import os
- openfile = eg.fileopenbox(filetypes=['*.txt'])
- f = open(openfile)
- filename = os.path.basename(openfile)
- file =eg.textbox(msg='文件【%s】的内容如下'%(filename),title='显示文件内容',\
- text=f)
- f.seek(0,0)
- list_f = f.read()
- if list_f != file[:-1]:
- choice = eg.indexbox(msg='检测到文件内容发生改变,请选择一下操作',title='警告',\
- choices=['覆盖保存','放弃保存','另存为...'])
- if choice == 0:
- f.close()
- f = open(openfile,'wt')
- f.write(file[:-1])
- f.close
复制代码
写到这里我试着运行了一下,使用idle运行时,不管在textbox中如何修改,程序运行完之后文本文件中没有任何内容。
但如果直接运行py文件,文本会按照textbox中修改的内容而发生变化。
小甲鱼的翻译的easygui文档(http://bbs.fishc.com/forum.php?mod=viewthread&tid=46069&extra=page%3D1%26filter%3Dtypeid%26typeid%3D403)中最开始就有说建议不要在idle上运行easygui以免发生冲突。我遇到的这个问题是否是因为这个冲突所造成的?如果是的话,为什么别的程序能正常运行,而这个程序却不能? |
|