probleme avec insertion images
salut. je veux créer une une fenêtre pour afficher 2 images différentes (an appuyant sur 1 des 2 buttons). voila le code mais il marche pas :)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
from Tkinter import *
#Variables globales
# taille de l'image
l = 300
h = 300
# tableau indexe par des noms
f = {'largeur':l,'hauteur':h,'cadre':None,'image':None}
fen3=Tk()
#fonction effacer
def img_pgm():
photo=PhotoImage(file="image.pgm") # ouverture de l'image pgm
largeur=photo.width(); hauteur=photo.height() # determination des dimensions
img=fond.create_image(largeur/2+1, hauteur/2+1,image=photo)
fen3.geometry(str(largeur+2)+'x'+str(hauteur+30))
fen3.title(str(largeur)+'x'+str(hauteur))
def img_ppm():
photo=PhotoImage(file="image.ppm") # ouverture de l'image ppm
largeur=photo.width(); hauteur=photo.height() # determination des dimensions
img=fond.create_image(largeur/2+1, hauteur/2+1,image=photo)
fen3.geometry(str(largeur+2)+'x'+str(hauteur+30))
fen3.title(str(largeur)+'x'+str(hauteur))
fond=Canvas(fen3, height=h, width=l)
fond.pack()
bout1=Button(fen3,text='quitter', command=fen3.quit)
bout1.pack(side=LEFT)
bout3=Button(fen3,text='image PGM', command=img_pgm) # afficher l'image pgm
bout3.pack(side=LEFT)
bout4=Button(fen3,text='image PPM', command=img_ppm)# afficher l'image ppm
bout4.pack(side=RIGHT)
#fen3.resizable(width=False, height=False)
fen3.mainloop()
fen3.destroy() |
merci ;)