admin 管理员组

文章数量: 887032


2024年2月23日发(作者:怎么介绍编程)

用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()

```


本文标签: 编程 文本编辑 作者 代码