ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 26.10.2023
Просмотров: 28
Скачиваний: 2
ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.
Қазақстан Респуликасы Білім және Ғылым министрлігі
Қ.Жұбанов атындағы Ақтөбе өңірлік университеті
Физика-Математика факультеті
Блакнот
(Қарапайым тексттік редакторды жобалау)
Орындағандар:
Жамбулов С
Коенбаев Н
Бердібек А
Естанов А
ВТКО-303
Ақтөбе 2022
# Импортирование необходимых библиотек
from tkinter import *
import tkinter as tk
from tkinter.scrolledtext import ScrolledText
from tkinter import filedialog
from tkinter import messagebox,font
from tkinter import ttk
from datetime import datetime
import webbrowser
# Определение функции для создания нового документа
def new():
text.delete('1.0','end')
# Определение функции для создания нового окна
def new_window():
# Создание нового окна
root = tk.Tk()
root.geometry('500x500')
# Создание меню
menubar = Menu(root)
# Добавление пунктов меню "Файл"
file = Menu(menubar,tearoff = 0)
file.add_command(label="Жаңа",command=new) # Пункт "Новый документ"
file.add_command(label="Жаңа терезе",command=new_window) # Пункт "Новое окно"
file.add_command(label="Ашу",command=Open) # Пункт "Открыть"
file.add_command(label="Сақтау",command=save) # Пункт "Сохранить"
file.add_command(label="Қалай сақтау", command=save_as) # Пункт "Сохранить как"
file.add_separator() # Добавление разделителя
file.add_command(label="Шығу",command=exit) # Пункт "Выход"
menubar.add_cascade(label="Файл",menu=file,font=('verdana',10,'bold')) # Добавление меню "Файл"
# Добавление пунктов меню "Редактировать"
edit = Menu(menubar,tearoff = 0)
edit.add_command(label="Кері",command=undo) # Пункт "Отменить"
edit.add_separator() # Добавление разделителя
edit.add_command(label="Қию",command=cut) # Пункт "Вырезать"
edit.add_command(label="Көшіру",command=copy) # Пункт "Копировать"
edit.add_command(label="Қою",command=paste) # Пункт "Вставить"
edit.add_command(label="Өшіру",command=delete) # Пункт "Удалить"
edit.add_command(label="Барлығын таңдау",accelerator="Ctrl+A",command=select_all) # Пункт "Выделить все"
edit.add_command(label="Уақыт",accelerator="F5",command=time) # Пункт "Вставить время"
menubar.add_cascade(label="Өзгерту",menu=edit) # Добавление меню "Редактировать"
# Create a new menu for Format options
Format = Menu(menubar, tearoff = 0)
Format.add_command(label="Шрифт", command=fonts)
menubar.add_cascade(label="Формат",menu=Format)
# Create a new menu for Help options
Help = Menu(menubar, tearoff = 0)
Help.add_command(label="Көмек",command=view_help)
Help.add_command(label="Туралы")
menubar.add_cascade(label="Көмек",menu=Help)
# Configure the main window with the new menu bar
root.config(menu=menubar)
# Create a new ScrolledText widget for the text editor
text = ScrolledText(root,width=1000,height=1000)
text.place(x=0,y=0)
# Start the main event loop of the window
root.mainloop()
def Open():
# Open file dialog to select file to open
root.filename = filedialog.askopenfilename(
initialdir = '/',
title="Select file",
filetypes=(("jpeg files","*.jpg"),("all files","*.*")))
# Open the selected file and read the contents into the text widget
file = open(root.filename)
text.insert('end',file.read())
def save():
# Placeholder function for saving the contents of the text widget
def save_as():
# Open file dialog to select a location to save the contents of the text widget
root.filename = filedialog.asksaveasfile(mode="w",defaultextension='.txt')
# If no file is selected, return
if root.filename is None:
return
# Write the contents of the text widget to the selected file
file_save = str(text.get(1.0,END))
root.filename.write(file_save)
root.filename.close()
def exit():
# Ask user if they want to save changes before closing the program
message = messagebox.askquestion('Блокнот',"Өзгерістерді сақтағыңыз келе ме?")
# If yes, save the changes and close the program
if message == "Ия":
save_as()
# If no, just close the program
else:
root.destroy()
def cut():
# Cut selected text from the text widget
text.event_generate("<
def copy():
# Copy selected text from the text widget
text.event_generate("<
def paste():
# Paste copied/cut text into the text widget
text.event_generate("<
>")
def delete():
# Ask user if they really want to delete all the text from the widget
message = messagebox.askquestion('Блокнот',"Бәрін өшіргіңіз келе ма?")
# If yes, delete all the text from the widget
if message == "иә":
text.delete('1.0','end')
else:
return "break"
def select_all():
# Select all the text in the text widget
text.tag_add('sel','1.0','end')
return 'break'
def time():
# Insert the current date and time at the end of the text widget
d = datetime.now()
text.insert('end',d)
def fonts():
# Create a new tkinter window
root = tk.Tk()
# Set the window geometry
root.geometry('400x400')
# Set the window title
root.title('Font')
# Create a label for the font selection
l1 = Label(root,text="Шрифт:")
l1.place(x=10,y=10)
# Create a combobox for the font selection
f = tk.StringVar()
fonts = ttk.Combobox(root, width = 15, textvariable = f, state='readonly',font=('verdana',10,'bold'),)
# Get the available font families and set them as the combobox values
fonts['values'] = font.families()
fonts.place(x=10,y=30)
# Set the default selected font family
fonts.current(0)
# Create a label for the font style selection
l2 = Label(root,text="Шрифт стилі:")
l2.place(x=180,y=10)
# Create a combobox for the font style selection
st = tk.StringVar()
style = ttk.Combobox(root, width = 15, textvariable = st, state='readonly',font=('verdana',10,'bold'),)
# Set the available font styles as the combobox values
style['values'] = ('bold','bold italic','italic')
style.place(x=180,y=30)
# Set the default selected font style
style.current(0)
# Create a label for the font size selection
l3 = Label(root,text="Өлшемі:")
l3.place(x=350,y=10)
# Create a combobox for the font size selection
sz = tk.StringVar()
size = ttk.Combobox(root, width = 2, textvariable = sz, state='readonly',font=('verdana',10,'bold'),)
# Set the available font sizes as the combobox values
size['values'] = (8,9,10,12,15,20,23,25,27,30,35,40,43,47,50,55,65,76,80,90,100,150,200,255,300)
size.place(x=350,y=30)
# Set the default selected font size
size.current(0)
# Create a label frame to display a sample of the selected font
sample = LabelFrame(root,text="Бастапқы",height=100,width=200)
# Set the label frame font to the currently selected font
sample['font'] = (fonts.get(),size.get(),style.get())
sample.place(x=180,y=220)
# Create a label to display the sample text
l4 = Label(sample,text="Бұл бастапқысы")
l4.place(x=20,y=30)