Python实现一个简单的记事本!这个都能拿到两百的外快

使用python实现一个记事本 , 实现了主要的功能 。
【Python实现一个简单的记事本!这个都能拿到两百的外快】# -*- coding: utf-8 -*-# @Time: 2020/10/13# @Author: aurora# @Site:# @File: note.py# @Version : 1.0# @Python Version : 3.7# @Software: PyCharmfrom tkinter import *from tkinter.filedialog import *from tkinter.messagebox import *from tkinter import scrolledtextimport osfilename = ''def author():# 定义作者函数showinfo(title="作者", message="aurora")# tkinter.messagebox 模块中的showinfo()函数展示一个小的图形用户界面(弹窗) 展示文本message信息def power():# 定义版权函数showinfo(title="版权信息", message="版权归aurora所有")def edition():showinfo(title="版本号", message="version 1.0")def new_file(*args):# 新建文件可变长参数global top, filename, textPad# 全局变量top.title("未命名文件")# 界面标题由记事本改为 未命名文件filename = None# 文件名textPad.delete(1.0, END)#???def open_file(*args):# 打开文件global filename# 全局变量 文件名filename = askopenfilename(defaultextension=".txt")#if filename == "":filename = Noneelse:top.title("" + os.path.basename(filename))# 系统路径文件名textPad.delete(1.0, END)f = open(filename, 'r', encoding="utf-8")# 打开文件 新建文件对象f利用open函数 指定文件名 操作模式r(默认) 写入编码方式 utf—8textPad.insert(1.0, f.read())f.close()# 关闭文件对象def click_open(event):# 点击打开global filenametop.title("" + os.path.basename(filename))# 调用系统的方法textPad.delete(1.0, END)f = open(filename, 'r', encoding="utf-8")textPad.insert(1.0, f.read())# 读入f.close()def save(*args):# 保存global filenametry:f = open(filename, 'w', encoding="utf-8")msg = textPad.get(1.0, 'end')f.write(msg)f.close()except:save_as()# 如果不能保存 , 就执行另存为的函数save_asdef save_as(*args):# 另存为global filenamef = asksaveasfilename(initialfile="未命名.txt", defaultextension=".txt")filename = ffh = open(f, 'w', encoding="utf-8")msg = textPad.get(1.0, END)fh.write(msg)fh.close()top.title("" + os.path.basename(f))def rename(newname):# 系统重命名函数global filenamename = os.path.basename(os.path.splitext(filename)[0])oldpath = filenamenewpath = os.path.dirname(oldpath) + '/' + newname + '.txt'os.rename(oldpath, newpath)filename = newpathrefresh()# 调用刷新函数def rename_file(*args):# 重命名global filenamet = Toplevel()t.geometry("260x80+200+250")t.title('重命名')frame = Frame(t)frame.pack(fill=X)lable = Label(frame, text="文件名")lable.pack(side=LEFT, padx=5)var = StringVar()e1 = Entry(frame, textvariable=var)e1.pack(expand=YES, fill=X, side=RIGHT)botton = Button(t, text="确定", command=lambda: rename(var.get()))botton.pack(side=BOTTOM, pady=10)def delete(*args):# 删除global filename, topchoice = askokcancel('提示', '要执行此操作吗')if choice:if os.path.exists(filename):os.remove(filename)textPad.delete(1.0, END)top.title("记事本")filename = ''def cut():# 剪切函数global textPadtextPad.event_generate("<>")def copy():# 复制函数global textPadtextPad.event_generate("<>")def paste():# 粘贴函数global textPadtextPad.event_generate("<>")def undo():# 撤销global textPadtextPad.event_generate("<>")def redo():# 重做global textPadtextPad.event_generate("