2.Закончить реализацию функции Open_file() 1.Добавить пункты меню как в оригинальном блокноте, функционал не обязательно.

from tkinter import *
from tkinter import filedialog

HEIGHT = 550
WIDTH = 550

root = Tk()
root.title('Блокнот')
root.geometry("%dx%d" % (WIDTH, HEIGHT))
root.resizable(True, True)
root.option_add('*Font', 'Calibri')
root.option_add('*Background', 'white')

menu = Menu(root)
root.config(menu=menu)

def open_file():
pass

def save_file():
file_name = filedialog.asksaveasfilename(initialdir='/', title='Select file',
filetypes=(('Text Documents', '*.txt'), ('all files', '*.*')))
if file_name:
f = open(file_name, 'w')
text_save = str(text.get(1.0, END))
f.write(text_save + '\n')
f.close()

file_menu = Menu(menu, tearoff=0)

file_menu.add_command(label='Создать')
file_menu.add_command(label='Открыть', command=open_file)
file_menu.add_command(label='Сохранить как', command=save_file)
file_menu.add_command(label='Выход', command=exit)

menu.add_cascade(label='Файл', menu=file_menu)

text = Text(root)
text.pack(expand=YES, fill=BOTH)

mainloop()

Danьka323323 Danьka323323    1   25.11.2020 13:29    0

Другие вопросы по теме Информатика