Оглавление:
Карта сайта:
Оглавление:
Карта сайта:
Модуль tkMessageBox используется для отображения окон сообщений в ваших приложениях. Этот модуль предоставляет ряд функций, которые вы можете использовать для отображения соответствующего сообщения.
Некоторые из этих функций: showinfo, showwarning, showerror, askquestion, askokcancel, askyesno и askretryignore.
Вот простой синтаксис для создания этого виджета -
tkMessageBox.FunctionName(title, message [, options])
Вы можете использовать одну из следующих функций с диалоговым окном -
from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") def hello(): messagebox.showinfo("Say Hello", "Hello World") B1 = Button(top, text = "Say Hello", command = hello) B1.place(x = 35,y = 50) top.mainloop()
from tkinter import * from tkinter import messagebox from tkinter import filedialog theme_colors = { 'dark':{ 'text_bg':"#343D46", # цвет фона 'text_fg':"#ffffff", # цвет текста 'cursor': "#EDA756", # цвет курсора 'select_bg':"#4E5A65" # цвет выделения }, 'light':{ 'text_bg': "#ffffff", # цвет фона 'text_fg': "#000000", # цвет текста 'cursor': "#8000ff", # цвет курсора 'select_bg': "#777777" # цвет выделения } } def changeTheme(theme): t['bg'] = theme_colors[theme]['text_bg'] t['fg'] = theme_colors[theme]['text_fg'] t['insertbackground'] = theme_colors[theme]['cursor'] t['selectbackground'] = theme_colors[theme]['select_bg'] def aboutProgramm(): mes = ''' Данный блокнот моя личная разработка, в ней отрабатываются навыки использования языка python ''' messagebox.showinfo(title='О программе', message=mes) def customQuit(): response = messagebox.askyesno(title='Выход', message='Закрыть программу') if response: root.destroy() def openFile(): file_pass = filedialog.askopenfilename( title = "Выбрать файл", filetypes = (("текстовые документы","*.txt"),("все файлы","*.*")), initialdir="D:\\docker\\python\\app2\\files" ) if file_pass: t.delete(1.0, END) file = open(file_pass, encoding='utf-8') text = file.read() t.insert('1.0', text) def saveFile(): file_pass = filedialog.asksaveasfilename( filetypes = ( ("текстовые документы (*.txt)", "*.txt"), ("все файлы", "*.*") ) ) f = open(file_pass,'w', encoding='utf-8') text = t.get('1.0', END) f.write(text) f.close() root = Tk() root.geometry('400x400') # Создаем меню main_menu = Menu(root) root.config(menu=main_menu) # Меню файл file_menu = Menu(main_menu, tearoff=0) file_menu.add_command(label='Открыть', command=openFile) file_menu.add_command(label='Сохранить', command=saveFile) file_menu.add_separator() file_menu.add_command(label='Выход', command=customQuit) main_menu.add_cascade(label='File', menu=file_menu) # Меню theme theme_menu = Menu(main_menu, tearoff=0) theme_menu_sub = Menu(theme_menu, tearoff=0) theme_menu_sub.add_command(label='Светлая тема', command = lambda : changeTheme('light')) theme_menu_sub.add_command(label='Темная тема', command = lambda : changeTheme('dark')) theme_menu.add_cascade(label='Темы', menu=theme_menu_sub) theme_menu.add_command(label='О программе', command=aboutProgramm) main_menu.add_cascade(label='Разное', menu=theme_menu) # Создаем фрейм для текстового ввода f_text = Frame(root) f_text.pack(fill=BOTH, expand=1) # Поле ввода t = Text(f_text, bg=theme_colors['dark']['text_bg'], fg=theme_colors['dark']['text_fg'], padx=10, # отступ по оси x pady=10, # отступ по оси y wrap=WORD, # Перенос слов insertbackground=theme_colors['dark']['cursor'], # цвет курсора selectbackground=theme_colors['dark']['select_bg'], # цвет выделения font=("Courier New", 12), spacing3=10, # Расстояние между строк width=30) t.pack(fill=BOTH, expand=1, side=LEFT) # Создаем скроллбар scroll = Scrollbar(f_text, command=t.yview) # Создаем скролл по оси y scroll.pack(fill=Y, side=LEFT) t.config(yscrollcommand=scroll.set) root.mainloop()
messagebox.showinfo(title='О программе', message=mes)
messagebox.askyesno(title='Выход', message='Закрыть программу')