2024年4月14日发(作者:)
用python写一个文本编辑器的代码
```
from tkinter import *
import sys
# Create window
window = Tk()
("Text editor")
ry("500x500")
# Create text box area
text_area = Text(window, font=("Arial", 12), height=200,
width=400)
text_()
# Create menubar
menu_bar = Menu(window)
# Create file menu
file_menu = Menu(menu_bar, tearoff=0)
# File command functions
def open_file():
file_name = nfilename(defaultextension=".txt",
filetypes=[("All Files", "*.*"),
("Text Documents", "*.txt")])
if file_name:
text_(1.0, END)
with open(file_name, "r") as file:
text_(1.0, ())
def save_file():
file_name =
easfilename(defaultextension=".txt",
filetypes=[("All Files", "*.*"),
("Text Documents", "*.txt")])
if file_name:
with open(file_name, "w") as file:
text_data = str(text_(1.0, END))
(text_data)
def quit():
()
()
# Add commands to file menu
file__command(label="Open", command=open_file)
file__command(label="Save", command=save_file)
file__command(label="Quit", command=quit)
# Add file menu to menubar
menu__cascade(label="File", menu=file_menu)
# Pack menubar and show window
(menu=menu_bar)
op()
```
发布者:admin,转转请注明出处:http://www.yc00.com/web/1713096194a2182197.html
评论列表(0条)