Problème avec un widget Canvas

pl29 Messages postés 1 Date d'inscription mardi 9 mars 2010 Statut Membre Dernière intervention 11 mai 2010 - 11 mai 2010 à 18:31
cs_laurent1024 Messages postés 987 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 30 août 2012 - 27 mai 2010 à 18:26
Bonjour,

Un problème pour afficher une image dans un widget Canvas :

Je voudrais que l'image apparaisse dans le Canvas suite au clic sur un bouton prévu à cet effet...

J'ai donc écrit ce code :

# -*- coding: cp1252 -*-

import Image
import ImageTk
import Tkinter
import tkFileDialog


fen = Tkinter.Tk()
fen.geometry('200x200')

def choixPhoto():
# Choix
fic = tkFileDialog.askopenfilename()
im = Image.open(fic)

# Reformatage
im.thumbnail((140,140))
ficThumb = fic[0 : fic.find('.')+1] + 'thumbnail.jpg'
im.save(ficThumb)

# Chargement
fic2 ImageTk.PhotoImage(file ficThumb)
x can.create_image(70, 70, image fic2)

can = Tkinter.Canvas(fen, bg='BLUE', height = 140, width = 140)
bouQuit Tkinter.Button(fen, text 'Quitter', command = fen.destroy)
bouAff Tkinter.Button(fen, text 'Afficher', command = choixPhoto)


bouAff.pack()
can.pack()
bouQuit.pack()


fen.mainloop()


qui ne plante pas mais ne m'affiche rien du tout.

Si quelqu'un peut m'expliquer mon(mes ?) erreurs, merci par avance

1 réponse

cs_laurent1024 Messages postés 987 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 30 août 2012 25
27 mai 2010 à 18:26
Il ne te manquerais pas déja des lignes du genre
fen.grid()

fen.can = Tkinter.Canvas(fen, bg='BLUE', height = 140, width = 140) 
fen.can.grid(column=0,row=0)

fen.bouQuit Tkinter.Button(fen, text 'Quitter', command = fen.destroy) 
fen.bouQuit.grid(column=1,row=0)

fen.bouAff Tkinter.Button(fen, text 'Afficher', command = choixPhoto)
fen.bouAff.grid(column=2,row=0)
0
Rejoignez-nous