Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import tkinter.simpledialog
- import tkinter.filedialog
- import tkinter.messagebox
- from PIL import Image, ImageTk
- def open_file():
- filetypes = [('All Image Formats', '.jpeg .jpg .png .tiff .bmp .gif'), ('All Files', '.*')]
- filename = tkinter.filedialog.askopenfilename(title='Select Image', filetypes=filetypes)
- if not filename:
- return
- print(filename)
- def save_file():
- filename = tkinter.filedialog.asksaveasfilename()
- if not filename:
- return
- print(filename)
- def share():
- def share_email():
- nonlocal popup
- popup.withdraw()
- email = tkinter.simpledialog.askstring('Wanna share by email?', 'Enter correct target email')
- print(email)
- popup.deiconify()
- popup.attributes('-topmost', True)#1
- def share_vk():
- pass
- def share_fb():
- pass
- popup = tk.Toplevel(root)
- popup.title('Wanna share?')
- popup.geometry(f'+{root.winfo_x() + root.winfo_width() // 4}+{root.winfo_y() + root.winfo_height() // 2}')#2
- tk.Button(popup, text='VK', width=20, command=share_vk).pack(side=tk.LEFT, padx=15, pady=10)
- tk.Button(popup, text='FB', width=20, command=share_fb).pack(side=tk.LEFT, padx=15, pady=10)
- tk.Button(popup, text='EMAIL', width=20, command=share_email).pack(side=tk.LEFT, padx=15, pady=10)
- popup.focus_set()
- #3
- def undo(event=None):
- global current_state
- if current_state-1 < 0:
- tk.messagebox.showerror(title='Error!', message='Not less than 0')
- return
- current_state -= 1
- print(STATES, current_state,sep='\n', end='\n\n')
- #3
- def redo(event=None):
- global current_state
- if current_state+1 > 5:
- tk.messagebox.showerror(title='Error!', message='Not more than 5')
- return
- current_state += 1
- print(STATES, current_state,sep='\n', end='\n\n')
- def reset():
- global current_state, STATES
- confirmed = tkinter.messagebox.askyesno('Confirm', 'All changes will be lost. Are you sure?')
- print(confirmed)
- if confirmed:
- current_state = 0
- STATES = STATES[:1]
- print(STATES, current_state,sep='\n', end='\n\n')
- def filter_1():
- global current_state
- STATES.insert(current_state+1, 'filter1')
- current_state += 1
- def filter_2():
- global current_state
- STATES.insert(current_state+1, 'filter2')
- current_state += 1
- def filter_3():
- global current_state
- STATES.insert(current_state+1, 'filter3')
- current_state += 1
- def filter_4():
- global current_state
- STATES.insert(current_state+1, 'filter4')
- current_state += 1
- def filter_5():
- global current_state
- STATES.insert(current_state+1, 'filter5')
- current_state += 1
- STATES = ['Initial']
- current_state = 0
- root = tk.Tk()
- root.title('TkFilters')
- root.configure(bg='white')
- button_style = {'fg': 'white', 'bg': 'black', 'font': ('Helvetica', 18)}
- grid_style = {'padx': 5, 'pady': 5, 'sticky': 'nwes'}
- open_button = tk.Button(root, **button_style, text='Open', command=open_file)
- save_button = tk.Button(root, text='Save As', command=save_file, **button_style)
- share_button = tk.Button(root, text='Share', command=share, **button_style)
- open_button.grid(column=1, row=0, **grid_style)
- save_button.grid(column=2, row=0, **grid_style)
- share_button.grid(column=3, row=0, **grid_style)
- undo_button = tk.Button(root, text='Undo', command=undo, **button_style)
- redo_button = tk.Button(root, text='Redo', command=redo, **button_style)
- reset_button = tk.Button(root, text='Reset', command=reset, **button_style)
- undo_button.grid(column=1, row=6, **grid_style)
- redo_button.grid(column=2, row=6, **grid_style)
- reset_button.grid(column=3, row=6, **grid_style)
- filter1_button = tk.Button(root, text='Filter1', command=filter_1, **button_style)
- filter2_button = tk.Button(root, text='Filter2', command=filter_2, **button_style)
- filter3_button = tk.Button(root, text='Filter3', command=filter_3, **button_style)
- filter4_button = tk.Button(root, text='Filter4', command=filter_4, **button_style)
- filter5_button = tk.Button(root, text='Filter5', command=filter_5, **button_style)
- filter1_button.grid(column=0, row=1, **grid_style)
- filter2_button.grid(column=0, row=2, **grid_style)
- filter3_button.grid(column=0, row=3, **grid_style)
- filter4_button.grid(column=0, row=4, **grid_style)
- filter5_button.grid(column=0, row=5, **grid_style)
- image_label = tk.Label(root)
- image_label.grid(row=1, column=1, rowspan=5, columnspan=3, sticky='nwes')
- #4
- image_src = Image.open(r'1.jpg')#Картинка должна находиться в одной папке с кодом
- image_tk = ImageTk.PhotoImage(image_src)
- image_label.configure(image=image_tk)
- root.bind('<Control-z>', undo)
- root.bind('<Control-y>', redo)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement