鱼C论坛

 找回密码
 立即注册
查看: 1056|回复: 1

[已解决]为什么无法保存文字到电脑

[复制链接]
发表于 2022-3-27 19:55:07 | 显示全部楼层 |阅读模式
5鱼币
为什么无法保存文字到电脑
源码:
  1. import easygui as eg
  2. import os

  3. while True:
  4.     choice = eg.buttonbox('欢迎进入光电记事本,请选择新建或打开','光电记事本',['新建','打开'])
  5.     if choice == '打开':
  6.         fileName = eg.fileopenbox(default = '*.txt')
  7.         temp = open(fileName,'r')
  8.         temp1 = ''
  9.         for each_line in temp:
  10.             temp1 = temp1 + each_line
  11.         temp.close
  12.         newWrite = eg.textbox(text = temp1,title = '光电记事本')
  13.         temp = open(fileName,'w')
  14.         temp.write(newWrite)
  15.         temp.close
  16.     else:
  17.         newWrite = eg.textbox(text = '',title = '光电记事本')
  18.         while True:
  19.             path = eg.enterbox('请输入文件保存的路径+文件名(不带后缀)','光电记事本')
  20.             try:
  21.                 temp = open(path+'.txt','w')
  22.                 temp.write(newWrite)
  23.                 temp.close

  24.                 break
  25.             except OSError:
  26.                 eg.msgbox('文件路径输入格式错误!示例:D:\\示例\\示例文件(示例文件.txt即保存在D盘的示例文件夹)','光电记事本')
复制代码

请输入原因和改好的代码!谢谢!
最佳答案
2022-3-27 19:55:08
本帖最后由 isdkz 于 2022-3-27 20:01 编辑


close() 都少了括号
  1. import easygui as eg
  2. import os

  3. while True:
  4.     choice = eg.buttonbox('欢迎进入光电记事本,请选择新建或打开','光电记事本',['新建','打开'])
  5.     if choice == '打开':
  6.         fileName = eg.fileopenbox(default = '*.txt')
  7.         temp = open(fileName,'r')
  8.         temp1 = ''
  9.         for each_line in temp:
  10.             temp1 = temp1 + each_line
  11.         temp.close()           # 这里少了括号
  12.         newWrite = eg.textbox(text = temp1,title = '光电记事本')
  13.         temp = open(fileName,'w')
  14.         temp.write(newWrite)
  15.         temp.close()            # 这里少了括号  
  16.     else:
  17.         newWrite = eg.textbox(text = '',title = '光电记事本')
  18.         while True:
  19.             path = eg.enterbox('请输入文件保存的路径+文件名(不带后缀)','光电记事本')
  20.             try:
  21.                 temp = open(path+'.txt','w')
  22.                 temp.write(newWrite)
  23.                 temp.close()         # 这里少了括号

  24.                 break
  25.             except OSError:
  26.                 eg.msgbox('文件路径输入格式错误!示例:D:\\示例\\示例文件(示例文件.txt即保存在D盘的示例文件夹)','光电记事本')
复制代码

最佳答案

查看完整内容

close() 都少了括号
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-3-27 19:55:08 | 显示全部楼层    本楼为最佳答案   
本帖最后由 isdkz 于 2022-3-27 20:01 编辑


close() 都少了括号
  1. import easygui as eg
  2. import os

  3. while True:
  4.     choice = eg.buttonbox('欢迎进入光电记事本,请选择新建或打开','光电记事本',['新建','打开'])
  5.     if choice == '打开':
  6.         fileName = eg.fileopenbox(default = '*.txt')
  7.         temp = open(fileName,'r')
  8.         temp1 = ''
  9.         for each_line in temp:
  10.             temp1 = temp1 + each_line
  11.         temp.close()           # 这里少了括号
  12.         newWrite = eg.textbox(text = temp1,title = '光电记事本')
  13.         temp = open(fileName,'w')
  14.         temp.write(newWrite)
  15.         temp.close()            # 这里少了括号  
  16.     else:
  17.         newWrite = eg.textbox(text = '',title = '光电记事本')
  18.         while True:
  19.             path = eg.enterbox('请输入文件保存的路径+文件名(不带后缀)','光电记事本')
  20.             try:
  21.                 temp = open(path+'.txt','w')
  22.                 temp.write(newWrite)
  23.                 temp.close()         # 这里少了括号

  24.                 break
  25.             except OSError:
  26.                 eg.msgbox('文件路径输入格式错误!示例:D:\\示例\\示例文件(示例文件.txt即保存在D盘的示例文件夹)','光电记事本')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-22 11:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表