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

<>")def select_all():# 全选global textPadtextPad.tag_add("sel", "1.0", "end")def find(*agrs):# 查找栏上面的查找界面global textPadt = Toplevel(top)t.title("查找")t.geometry("260x60+200+250")# 图形用户界面的大小t.transient(top)Label(t, text="查找:").grid(row=0, column=0, sticky="e")v = StringVar()e = Entry(t, width=20, textvariable=v)e.grid(row=0, column=1, padx=2, pady=2, sticky="we")e.focus_set()c = IntVar()Checkbutton(t, text="不区分大小写", variable=c).grid(row=1, column=1, sticky='e')Button(t, text="查找所有", command=lambda: search(v.get(), c.get(), textPad, t, e)).grid\(row=0, column=2, sticky="e" + "w", padx=2, pady=2)# 图形界面中的按钮def close_search():# 函数内部定义函数 关闭查找textPad.tag_remove("match", "1.0", END)t.destroy()t.protocol("WM_DELETE_WINDOW", close_search)def mypopup(event):# 弹出菜单global editmenueditmenu.tk_popup(event.x_root, event.y_root)def search(needle, cssnstv, textPad, t, e):# 文章内部进行查找 匹配的函数textPad.tag_remove("match", "1.0", END)count = 0if needle:start = 1.0while True:pos = textPad.search(needle, start, nocase=cssnstv, stopindex=END)if not pos:breakstrlist = pos.split('.')# 分割字符串left = strlist[0]right = str(int(strlist[1]) + len(needle))lastpos = left + '.' + righttextPad.tag_add("match", pos, lastpos)count += 1start = lastpostextPad.tag_config('match', background="yellow")# 查找到的元素变为高亮的黄色突出显示e.focus_set()t.title(str(count) + "个被匹配")#def refresh():# 刷新函数global top, filenameif filename:top.title(os.path.basename(filename))else:top.title("记事本")top = Tk()# 新建图形用户界面(主界面)top.title("记事本")# 顶层标题top.geometry("640x480+500+200")# 界面大小menubar = Menu(top)# 文件功能# Menu类控件用来实现顶层/下拉/弹出菜单filemenu = Menu(top)# 创建一个顶级菜单# 通过add_command函数添加一个下拉的子菜单filemenu.add_command(label="新建", accelerator="Ctrl+N", command=new_file)# 创建一个下拉菜单“新建” , 然后将它添加到顶级菜单中 command绑定点击后调用的函数filemenu.add_command(label="打开", accelerator="Ctrl+O", command=open_file)filemenu.add_command(label="保存", accelerator="Ctrl+S", command=save)filemenu.add_command(label="另存为", accelerator="Ctrl+shift+s", command=save_as)filemenu.add_command(label="重命名", accelerator="Ctrl+R", command=rename_file)filemenu.add_command(label="删除", accelerator="Ctrl+D", command=delete)menubar.add_cascade(label="文件(F)", menu=filemenu)# 文件# 编辑功能editmenu = Menu(top)editmenu.add_command(label="撤销", accelerator="Ctrl+Z", command=undo)editmenu.add_command(label="重做", accelerator="Ctrl+Y", command=redo)editmenu.add_separator()# 分割线editmenu.add_command(label="剪切", accelerator="Ctrl+X", command=cut)editmenu.add_command(label="复制", accelerator="Ctrl+C", command=copy)editmenu.add_command(label="粘贴", accelerator="Ctrl+V", command=paste)editmenu.add_separator()editmenu.add_command(label="查找", accelerator="Ctrl+F", command=find)editmenu.add_command(label="全选", accelerator="Ctrl+A", command=select_all)menubar.add_cascade(label="编辑(E)", menu=editmenu)# 编辑# 关于 功能aboutmenu = Menu(top)aboutmenu.add_command(label="作者", command=author)aboutmenu.add_command(label="版权", command=power)aboutmenu.add_command(label="版本", command=edition)#menubar.add_cascade(label="关于(A)", menu=aboutmenu)# 关于top['menu'] = menubarshortcutbar = Frame(top, height=25, bg='Silver')shortcutbar.pack(expand=NO, fill=X)textPad = Text(top, undo=True)textPad.pack(expand=YES, fill=BOTH)scroll = Scrollbar(textPad)textPad.config(yscrollcommand=scroll.set)scroll.config(command=textPad.yview)scroll.pack(side=RIGHT, fill=Y)# 热键绑定考虑大小写textPad.bind("


推荐阅读