from tkinter import *
from tkinter import filedialog
import sys
def cmopen():
file_path = filedialog.askopenfilename()
f=open(file_path, "r")
text.insert(0.0, f.read())
f.close()
def cmsave():
file = filedialog.asksaveasfile(defaultextension='.txt')
print(file.name)
lines=text.get(0.0, END)
print(lines)
f = open(file.name, 'w')
f.write(lines)
f.close
def cmexit():
sys.exit(0)
root = Tk()
root.geometry('500x500')
scrollbar = Scrollbar(root)
text = Text(root, yscrollcommand = scrollbar.set ,wrap=WORD,width=50)
text.place(x = 0 , y = 0)
mainmenu = Menu(root)
root.config(menu=mainmenu)
filemenu = Menu(mainmenu, tearoff=0)
filemenu.add_command(label="Открыть файл",command=cmopen)
filemenu.add_command(label="Сохранить",command=cmsave)
filemenu.add_command(label="Выход",command=cmexit)
mainmenu.add_cascade(label="Команды", menu=filemenu)
root.mainloop()
|