Advertisement
1400_SpaceCat

Bad Program / Virtual Reader

Aug 4th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.73 KB | None | 0 0
  1. #-*- coding:utf-8 -*-#
  2. #Проверка версии python (2.x.x или 3.x.x)#
  3. try:
  4.     from Tkinter import *
  5.     from tkFileDialog import askopenfilename
  6.    
  7. except ImportError:
  8.  
  9.     from tkinter import *
  10.     from tkinter.filedialog import askopenfilename
  11.  
  12. from re import sub
  13. from os.path import splitext,split,join,expanduser
  14.  
  15. class Viewer:
  16.     def block_close_button(self,event=None):
  17.         pass
  18.    
  19.     def programs_information(self):
  20.  
  21.         #Параметры виджета#
  22.         info_widget = Toplevel()
  23.         info_widget.title("Информация")
  24.         info_widget.geometry("595x650+650+100")
  25.         info_widget.resizable(0,0)
  26.  
  27.         #Ввод данных#
  28.         information = Text(info_widget)
  29.         information.insert(END,open("files/information.txt").read())
  30.         text= Text(info_widget,font=("consolas",12),width=100,height=100)
  31.         text.pack()
  32.  
  33.         text.insert(1.0,information)
  34.    
  35.    
  36.     def filename_changer(self,text_path):
  37.        
  38.         (path, text_name) = split(text_path)
  39.  
  40.         #Преобразование text в img#
  41.         cuted_name  = sub("[^\d+]","", text_name)
  42.         image_name  = ("image_n"+str(cuted_name)+".gif")
  43.         return join(path, image_name)
  44.    
  45.     def __init__(self, master):
  46.  
  47.         frame = Frame(master)
  48.         frame.pack()
  49.        
  50.         #Объявление кнопок#
  51.         self.button_quit = Button(buttons_place, text="Выход", command=frame.quit)
  52.         self.button_quit.pack(side=LEFT)
  53.        
  54.         self.button_info = Button(buttons_place, text="Информация", command=self.programs_information)
  55.         self.button_info.pack(side=LEFT)
  56.  
  57.         #Настройка полосы прокрутки#
  58.         self.yscrollbar = Scrollbar(text_place)
  59.         self.yscrollbar.pack(side=RIGHT, fill=Y)
  60.        
  61.         #Объявление текстового поля#
  62.         self.text = Text(text_place, wrap=WORD, font=("times",14),
  63.                          padx=2,pady=2, height=150,width=150,
  64.                          yscrollcommand=self.yscrollbar.set)
  65.        
  66.         self.text.pack()
  67.        
  68.         self.yscrollbar.config(command=self.text.yview)
  69.        
  70.         #Открытие папки с файлами#
  71.         self.choosen_text = askopenfilename(
  72.                     parent=text_place,
  73.                     title='',
  74.                     initialdir=expanduser(u'files/'),
  75.                     filetypes=[('TXT files', '.txt'),('GIF images', '.gif')])
  76.        
  77.         self.text.insert(END, open(self.choosen_text).read())
  78.        
  79.         #Обращение к функции filename_changer#
  80.         self.choosen_image = self.filename_changer(self.choosen_text)
  81.        
  82.         #Присвоение изображения к виджету#
  83.         self.image_linky = PhotoImage(file=self.choosen_image)
  84.         self.image_puton = Label(frame,image=self.image_linky)
  85.         self.image_puton.pack(side=TOP)
  86.  
  87. ###############################################################
  88. buttons_place = Tk()
  89. buttons_place.title("Управление")
  90. buttons_place.geometry("176x30+0+0")
  91. buttons_place.resizable(0,0)
  92.  
  93. image_window = Toplevel()
  94. image_window.title("Изображения")
  95. image_window.geometry("600x400+500+300")
  96.  
  97. text_place = Toplevel(bg="white",relief=FLAT)
  98. text_place.geometry("800x600+200+100")
  99. text_place.title("Текст")
  100.  
  101. call_class = Viewer(image_window)
  102.  
  103. #Обращение к функции block_close_button#
  104. buttons_place.protocol('WM_DELETE_WINDOW', Viewer.block_close_button)
  105. text_place.protocol('WM_DELETE_WINDOW',    Viewer.block_close_button)
  106. image_window.protocol('WM_DELETE_WINDOW',  Viewer.block_close_button)
  107.  
  108. image_window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement