from tkinter import *
from tkinter import filedialog
from tkinter import ttk
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():
exit()
def setsizefont(stext):
global text
text['font'] = ('Arial',int(stext) , 'bold')
textsize = int(stext)
def winsize():
window = Tk()
window.title("Размер шрифта")
window.geometry("500x300")
e1 = Entry(window,width=50,text="20")
e1.insert(0, "25")
e1.pack(pady=15)
b1 = Button(window,text="Изменить", width=15, height=3,command=lambda: setsizefont(e1.get()))
b1.pack()
def setnamefont(stext):
global text
text['font'] = (str(stext),textsize , 'bold')
def winname():
window = Tk()
window.title("Имя шрифта")
window.geometry("500x300")
namefonts = ["Arial", "Comic Sans MS", "Georgia", "Lucida Console"]
combobox = ttk.Combobox(window,values=namefonts)
combobox.current(0)
combobox.pack(pady=15)
b1 = Button(window,text="Изменить", width=15, height=3,command=lambda: setnamefont(combobox.get()))
b1.pack()
root = Tk()
root.geometry('500x500')
root.title("Ptext")
scrollbar = Scrollbar(root)
textsize = 16
text = Text(root, yscrollcommand = scrollbar.set ,wrap=WORD,width=50,font= ('Arial', textsize, 'bold'))
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)
fmenu = Menu(mainmenu, tearoff=0)
fmenu.add_command(label="Размер шрифта",command=winsize)
fmenu.add_command(label="Имя шрифта",command=winname)
mainmenu.add_cascade(label="Форматирование",menu=fmenu)
root.mainloop()
|