samedi 28 février 2015

Adding an Image to a Canvas Using AskOpenFileName

I'm trying to get a .gif image to go into a canvas after selected from my PC using filedialog.askopenfilename(). The canvas will take the image if I (1) don't put it in a def and (2) do not use the filedialog, but I can't see why this would not work ....



from tkinter import *
root=Tk()
root.geometry("600x600")
root.config(background="#FFFFFF")

canvas = Canvas(width=200,height=200)
canvas.grid(row=0,column=0)


def create_image():
profileimage = filedialog.askopenfilename()
i = PhotoImage(file=profileimage)
canvas.create_image(0,0,image=i)

b = Button(text="Click", command=create_image).grid(row=1,column=0)

Aucun commentaire:

Enregistrer un commentaire