New to programming and especially python and tKinter. How can I create a way to bind the key "s" to the button or the function sharpen
? Any help would be awesome.
from Tkinter import *
from PIL import Image, ImageTk, ImageFilter, ImageEnhance
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
master.wm_title("Image examples")
self.pack()
self.createWidgets()
def createWidgets(self):
self.img = Image.open("lineage.jpg")
self.photo1 = ImageTk.PhotoImage(self.img.convert("RGB"))
self.label1 = Label(self, image=self.photo1)
self.label1.grid(row=0, column=0, padx=5, pady=5, rowspan=10)
self.photo2 = ImageTk.PhotoImage(self.img.convert("RGB"))
self.label2 = Label(self, image=self.photo2)
self.label2.grid(row=0, column=1, padx=5, pady=5, rowspan=10)
button5 = Button(self, text="Sharpen", command=self.sharpen)
button5.grid(row=4, column= 2, sticky = N)
def sharpen(self):
img2 = self.img.filter(ImageFilter.SHARPEN)
self.photo2 = ImageTk.PhotoImage(img2)
self.label2 = Label(self, image=self.photo2)
self.label2.grid(row=0, column=1, padx=5, pady=5, rowspan=10)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…