1234567891011121314151617181920212223242526 |
- from tkinter import *
- from tkinter import filedialog
- root = Tk()
- root.geometry('400x300')
- root.title('Текстовый редактор')
- root.resizable(False, False)
- def file_open():
- url = filedialog.askopenfilename()
- f = open(url)
- text.delete(0.0, END)
- text.insert(0.0, f.read())
- f.close()
- def file_save():
- url = filedialog.asksaveasfilename()
- f = open(url, 'w')
- f.write(text.get(0.0, END))
- f.close()
- rootmenu = Menu(root)
- root.config(menu = rootmenu)
- fm = Menu(rootmenu, tearoff = 0)
- fm.add_command(label = 'Открыть', command = file_open)
- fm.add_command(label = 'Сохранить', command = file_save)
- rootmenu.add_cascade(label = 'Файл', menu = fm)
- text = Text(width = 300, height = 400)
- text.pack()
- root.mainloop()
|