Advertisement
PorisulkiP

Untitled

Apr 2nd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.83 KB | None | 0 0
  1. import tkinter as  tk
  2. import tkinter.simpledialog
  3. import tkinter.filedialog
  4. import tkinter.messagebox
  5. from PIL import Image, ImageTk
  6.  
  7. def open_file():
  8.     filetypes = [('All Image Formats', '.jpeg .jpg .png .tiff .bmp .gif'), ('All Files', '.*')]
  9.     filename = tkinter.filedialog.askopenfilename(title='Select Image', filetypes=filetypes)
  10.     if not filename:
  11.         return
  12.     print(filename)
  13.  
  14.  
  15. def save_file():
  16.     filename = tkinter.filedialog.asksaveasfilename()
  17.     if not filename:
  18.         return
  19.     print(filename)
  20.  
  21. def share():
  22.     def share_email():
  23.         nonlocal popup
  24.         popup.withdraw()
  25.         email = tkinter.simpledialog.askstring('Wanna share by email?', 'Enter correct target email')
  26.         print(email)
  27.         popup.deiconify()
  28.         popup.attributes('-topmost', True)#1
  29.  
  30.     def share_vk():
  31.         pass
  32.  
  33.     def share_fb():
  34.         pass
  35.  
  36.     popup = tk.Toplevel(root)
  37.     popup.title('Wanna share?')
  38.    
  39.     popup.geometry(f'+{root.winfo_x() + root.winfo_width() // 4}+{root.winfo_y() + root.winfo_height() // 2}')#2
  40.     tk.Button(popup, text='VK', width=20, command=share_vk).pack(side=tk.LEFT, padx=15, pady=10)
  41.     tk.Button(popup, text='FB', width=20, command=share_fb).pack(side=tk.LEFT, padx=15, pady=10)
  42.     tk.Button(popup, text='EMAIL', width=20, command=share_email).pack(side=tk.LEFT, padx=15, pady=10)
  43.     popup.focus_set()
  44.  
  45. #3
  46. def undo(event=None):
  47.     global current_state
  48.     if current_state-1 < 0:
  49.         tk.messagebox.showerror(title='Error!', message='Not less than 0')
  50.         return
  51.     current_state -= 1
  52.     print(STATES, current_state,sep='\n', end='\n\n')
  53.  
  54. #3
  55. def redo(event=None):
  56.     global current_state
  57.     if current_state+1 > 5:
  58.         tk.messagebox.showerror(title='Error!', message='Not more than 5')
  59.         return
  60.     current_state += 1
  61.     print(STATES, current_state,sep='\n', end='\n\n')
  62.  
  63.  
  64. def reset():
  65.     global current_state, STATES
  66.     confirmed = tkinter.messagebox.askyesno('Confirm', 'All changes will be lost. Are you sure?')
  67.     print(confirmed)
  68.     if confirmed:
  69.         current_state = 0
  70.         STATES = STATES[:1]  
  71.     print(STATES, current_state,sep='\n', end='\n\n')
  72.  
  73.  
  74. def filter_1():
  75.     global current_state
  76.     STATES.insert(current_state+1, 'filter1')
  77.     current_state += 1
  78.  
  79.  
  80. def filter_2():
  81.     global current_state
  82.     STATES.insert(current_state+1, 'filter2')
  83.     current_state += 1
  84.  
  85.  
  86. def filter_3():
  87.     global current_state
  88.     STATES.insert(current_state+1, 'filter3')
  89.     current_state += 1
  90.  
  91.  
  92. def filter_4():
  93.     global current_state
  94.     STATES.insert(current_state+1, 'filter4')
  95.     current_state += 1
  96.  
  97.  
  98. def filter_5():
  99.     global current_state
  100.     STATES.insert(current_state+1, 'filter5')
  101.     current_state += 1
  102.  
  103.  
  104.  
  105. STATES = ['Initial']
  106. current_state = 0
  107.  
  108. root = tk.Tk()
  109.  
  110.  
  111. root.title('TkFilters')
  112. root.configure(bg='white')
  113.  
  114.  
  115. button_style = {'fg': 'white', 'bg': 'black', 'font': ('Helvetica', 18)}
  116. grid_style = {'padx': 5, 'pady': 5, 'sticky': 'nwes'}
  117.  
  118.  
  119. open_button = tk.Button(root, **button_style, text='Open', command=open_file)
  120. save_button = tk.Button(root, text='Save As', command=save_file,  **button_style)
  121. share_button = tk.Button(root, text='Share', command=share,  **button_style)
  122.  
  123. open_button.grid(column=1, row=0, **grid_style)
  124. save_button.grid(column=2, row=0, **grid_style)
  125. share_button.grid(column=3, row=0, **grid_style)
  126.  
  127.  
  128. undo_button = tk.Button(root, text='Undo', command=undo, **button_style)
  129. redo_button = tk.Button(root, text='Redo', command=redo, **button_style)
  130. reset_button = tk.Button(root, text='Reset', command=reset, **button_style)
  131.  
  132. undo_button.grid(column=1, row=6, **grid_style)
  133. redo_button.grid(column=2, row=6, **grid_style)
  134. reset_button.grid(column=3, row=6, **grid_style)
  135.  
  136.  
  137. filter1_button = tk.Button(root, text='Filter1', command=filter_1, **button_style)
  138. filter2_button = tk.Button(root, text='Filter2', command=filter_2, **button_style)
  139. filter3_button = tk.Button(root, text='Filter3', command=filter_3, **button_style)
  140. filter4_button = tk.Button(root, text='Filter4', command=filter_4, **button_style)
  141. filter5_button = tk.Button(root, text='Filter5', command=filter_5, **button_style)
  142.  
  143. filter1_button.grid(column=0, row=1, **grid_style)
  144. filter2_button.grid(column=0, row=2, **grid_style)
  145. filter3_button.grid(column=0, row=3, **grid_style)
  146. filter4_button.grid(column=0, row=4, **grid_style)
  147. filter5_button.grid(column=0, row=5, **grid_style)
  148.  
  149.  
  150. image_label = tk.Label(root)
  151. image_label.grid(row=1, column=1, rowspan=5, columnspan=3, sticky='nwes')
  152. #4
  153. image_src = Image.open(r'1.jpg')#Картинка должна находиться в одной папке с кодом
  154. image_tk = ImageTk.PhotoImage(image_src)
  155.  
  156. image_label.configure(image=image_tk)
  157.  
  158.  
  159. root.bind('<Control-z>', undo)
  160. root.bind('<Control-y>', redo)
  161. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement