Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*- coding:utf-8 -*-#
- #Проверка версии python (2.x.x или 3.x.x)#
- try:
- from Tkinter import *
- from tkFileDialog import askopenfilename
- except ImportError:
- from tkinter import *
- from tkinter.filedialog import askopenfilename
- from re import sub
- from os.path import splitext,split,join,expanduser
- class Viewer:
- def block_close_button(self,event=None):
- pass
- def programs_information(self):
- #Параметры виджета#
- info_widget = Toplevel()
- info_widget.title("Информация")
- info_widget.geometry("595x650+650+100")
- info_widget.resizable(0,0)
- #Ввод данных#
- information = Text(info_widget)
- information.insert(END,open("files/information.txt").read())
- text= Text(info_widget,font=("consolas",12),width=100,height=100)
- text.pack()
- text.insert(1.0,information)
- def filename_changer(self,text_path):
- (path, text_name) = split(text_path)
- #Преобразование text в img#
- cuted_name = sub("[^\d+]","", text_name)
- image_name = ("image_n"+str(cuted_name)+".gif")
- return join(path, image_name)
- def __init__(self, master):
- frame = Frame(master)
- frame.pack()
- #Объявление кнопок#
- self.button_quit = Button(buttons_place, text="Выход", command=frame.quit)
- self.button_quit.pack(side=LEFT)
- self.button_info = Button(buttons_place, text="Информация", command=self.programs_information)
- self.button_info.pack(side=LEFT)
- #Настройка полосы прокрутки#
- self.yscrollbar = Scrollbar(text_place)
- self.yscrollbar.pack(side=RIGHT, fill=Y)
- #Объявление текстового поля#
- self.text = Text(text_place, wrap=WORD, font=("times",14),
- padx=2,pady=2, height=150,width=150,
- yscrollcommand=self.yscrollbar.set)
- self.text.pack()
- self.yscrollbar.config(command=self.text.yview)
- #Открытие папки с файлами#
- self.choosen_text = askopenfilename(
- parent=text_place,
- title='',
- initialdir=expanduser(u'files/'),
- filetypes=[('TXT files', '.txt'),('GIF images', '.gif')])
- self.text.insert(END, open(self.choosen_text).read())
- #Обращение к функции filename_changer#
- self.choosen_image = self.filename_changer(self.choosen_text)
- #Присвоение изображения к виджету#
- self.image_linky = PhotoImage(file=self.choosen_image)
- self.image_puton = Label(frame,image=self.image_linky)
- self.image_puton.pack(side=TOP)
- ###############################################################
- buttons_place = Tk()
- buttons_place.title("Управление")
- buttons_place.geometry("176x30+0+0")
- buttons_place.resizable(0,0)
- image_window = Toplevel()
- image_window.title("Изображения")
- image_window.geometry("600x400+500+300")
- text_place = Toplevel(bg="white",relief=FLAT)
- text_place.geometry("800x600+200+100")
- text_place.title("Текст")
- call_class = Viewer(image_window)
- #Обращение к функции block_close_button#
- buttons_place.protocol('WM_DELETE_WINDOW', Viewer.block_close_button)
- text_place.protocol('WM_DELETE_WINDOW', Viewer.block_close_button)
- image_window.protocol('WM_DELETE_WINDOW', Viewer.block_close_button)
- image_window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement