from tkinter import filedialog
import tkinter as tk
import tkinter.scrolledtext as tkst
from tkinter import messagebox
import fileinput
from tkinter import *
from os import *
import os
import time
t1 = []root = None
def die():
root.destroy()
def about():
messagebox.showinfo(title = "当前版本为1.0,欢迎使用",message = "**作者:韩东n**状态:继续努力ing")
class editor:
def __init__(self,rt):
if rt == None:
self.t = tk.Tk()
else:
self.t = tk.Toplevel(rt)
self.t.title("文本编辑器%d" % (len(t1)+1))
self.bar = tk.Menu(rt)
self.filem = tk.Menu(self.bar)
self.filem.add_separator()
self.filem.add_command(label = "新建",command = self.neweditor)
self.filem.add_separator()
self.filem.add_command(label = "打开",command = self.openfile)
self.filem.add_separator()
self.filem.add_command(label = "保存",command = self.savefile)
self.filem.add_separator()
self.filem.add_command(label = "关闭",command = self.close)
self.filem.add_separator()
self.filem.add_command(label = "退出",command = die)
self.editm = tk.Menu(self.bar)
self.editm.add_separator()
self.editm.add_command(label = "复制",command = self.copy)
self.editm.add_separator()
self.editm.add_command(label = "黏贴",command = self.paste)
self.editm.add_separator()
self.editm.add_command(label = "剪切",command = self.cut)
self.editm.add_separator()
self.editm.add_command(label = "删除",command = self.delete_text)
self.editm.add_separator()
self.editm.add_command(label = "查找",command = self.find_char)
self.editm.add_separator()
self.editm.add_command(label = "全选",command = self.select_char_all)
self.helpm = tk.Menu(self.bar)
self.helpm.add_command(label = "关于",command = about)
self.bar.add_cascade(label = "文件",menu = self.filem)
self.bar.add_cascade(label = "编辑",menu = self.editm)
self.bar.add_cascade(label = "帮助",menu = self.helpm)
self.t.config(menu = self.bar)
self.f = tk.Frame(self.t,width = 512)
self.f.pack(expand =1)
self.st = tkst.ScrolledText(self.t)
self.st.pack(expand = 1)
def close(self):
self.t.destroy()
def openfile(self):
oname = filedialog.askopenfilename(filetypes = [("打开文件","*.txt")])
if oname:
for line in fileinput.input(oname):
self.st.insert("1.0",line)
self.t.title(oname)
def savefile(self):
sname = filedialog.asksaveasfilename(title = "保存好你的宝宝哟",filetypes = [("保存文件","*.txt")])
if sname:
ofp = open(sname,"a")
ofp.write(self.st.get(1.0,tk.END))
ofp.flush()