from tkinter import *
from tkinter.filedialog import askopenfile, asksaveasfile, askopenfilename, asksaveasfilename
import os
from pygments import highlight
counter = 1
class TextEditor:
def donothing(self):
self.filewin = Toplevel(self.root)
button = Button(self.filewin, text="Do not do anything")
button.pack()
def open_file(self):
self.file = askopenfile(mode='r')
if self.file is not None:
self.text.delete(1.0, "end-1c")
content = self.file.read()
self.filename = self.file.name
self.text.insert(INSERT, content)
self.filename_only = self.filename.split("/")[-1]
self.root.title(self.filename_only+"-Notepad")
def save_file(self):
if(self.filename != None and self.file != None):
f = open(self.filename, "r+")
f.seek(0)
f.truncate()
self.text_data = self.text.get(1.0, "end-1c")
f.write(self.text_data)
else:
self.file = asksaveasfile()
self.filename = self.file.name
self.text_data = self.text.get(1.0, "end-1c")
f = open(self.filename, "r+")
f.write(self.text_data)
self.filename_only = self.filename.split("/")[-1]
self.root.title(self.filename_only+"-Notepad")
def save_as_file(self):
self.file = asksaveasfile()
self.filename = self.file.name
self.text_data = self.text.get(1.0, "end-1c")
f = open(self.filename, "r+")
f.write(self.text_data)
self.filename_only = self.filename.split("/")[-1]
self.root.title(self.filename_only+"-Notepad")
def close_file(self):
self.text.delete(1.0,"end-1c")
self.root.title("Untitled"+"-Notepad")
self.file.close()
self.file = None
self.filename = None
def new(self):
global counter,win
counter +=1
win[counter] = TextEditor()
def dark(self):
self.text.config(foreground = "white",background="black",insertbackground="white")
def light(self):
self.text.config(foreground = "black",background="white",insertbackground="black")
def __init__(self):
self.root = Tk()
scrollbar = Scrollbar(self.root)
scrollbar.pack(side=RIGHT, fill=Y)
self.root.title("Untitled-Notepad")
self.file = None
self.filename = None
menubar = Menu(self.root)
self.filemenu = Menu(menubar, tearoff=0)
self.filemenu.add_command(label="New", command=self.new)
self.filemenu.add_command(label="Open", command=self.open_file)
self.filemenu.add_command(label="Save", command=self.save_file)
self.filemenu.add_command(label="Save as...", command=self.save_as_file)
self.filemenu.add_command(label="Close", command=self.close_file)
self.filemenu.add_separator()
self.filemenu.add_command(label="Exit", command=self.root.quit)
menubar.add_cascade(label="File", menu=self.filemenu)
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Dark", command=self.dark)
editmenu.add_command(label="Light", command=self.light)
menubar.add_cascade(label="Theme", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help Index", command=self.donothing)
helpmenu.add_command(label="About...", command=self.donothing)
menubar.add_cascade(label="Help", menu=helpmenu)
self.root.config(menu=menubar)
self.text = Text(self.root)
self.text.pack()
self.text.tag_add("here", "1.0", "1.4")
self.text.tag_add("start", "1.8", "1.13")
self.text.tag_config("here", background="yellow", foreground="blue")
self.text.tag_config("start", background="aqua", foreground="green")
self.text.config(insertbackground="black")
self.root.mainloop()
win = dict()
win[counter] = TextEditor()
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
记事本应用程序仅使用 Python 编程语言构建。该系统设计为用户友好型,可以轻松集成到您工作的任何系统中。该项目使用 tkinter 库为您的 Python 应用程序提供增强的 GUI。该应用程序模仿实际的记事本功能,允许您编写文本或将其用于编码目的。它还使您能够以各种文本格式保存您的工作。此应用程序旨在简化为您的项目创建文本文件的过程。 在 Python 中使用 Tkinter 的记事本应用程序与源代码安装指南 首先,您需要下载并安装Python IDLE,这是链接“https://www.python.org/downloads/”。 下载此站点的源代码。 找到并解压缩 zip 文件。 打开解压缩的文件夹 找到 py 文件。 然后通过 python IDLE 或任何支持 python 语言的 IDE 打开文件。 运行 py 文件以启动程序。
资源推荐
资源详情
资源评论
























收起资源包目录



共 1 条
- 1
资源评论



新华
- 粉丝: 1w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 网络营销方法与策略.pptx
- 电控联网教学实训系统安全操作规程.doc
- 基于粒子群算法的TSP问题设计研究.doc
- 小学英语网络学习体会.doc
- 中小型企业网络构建毕业论文.doc
- 自动化生产线简介.ppt
- 项目管理班子人员.docx
- 工程项目管理基础PPT课件.ppt
- 信息系统安全方案加密机制.doc
- 综合布线工程设计规范.doc
- 电子商务专业职业规划.doc
- 最新网络安全基础应用与标准(第4版)(清华大学出版社)期末复习总结资料------.pdf
- 学校网络信息安全管理责任书.docx
- LabVIEW基于ONNX的神经网络交互工具包
- 智能家居销售人员的真实有感相信能帮助您(最新整理).pdf
- 政府门户网站持续发展的动力探讨.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
