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 43 44 45 46 47 48 49 50 51
| #!/usr/bin/python
# -*- coding: utf-8 -*-
from Tkinter import *
from PIL import Image, ImageTk
class Application:
def __init__(self):
self.root=Tk()
self.root.rowconfigure(0,weight=1)
self.root.columnconfigure(0,weight=1)
my_file = "test.jpg"
self.image = Image.open(my_file)
self.can=Canvas(self.root)
self.can.bind("<Configure>",self.resize)
self.can.grid(sticky=NSEW)
self.can.create_text(30, 30, anchor =NW, text ='Un ptit texte',font=('Papyrus', 30, 'normal'), fill ='red')
self.can.create_text(30, 70, anchor =NW, text ='Un ptit texte',font=('Papyrus', 30, 'normal'), fill ='blue')
def resize(self,event):
self.img=self.image.resize((event.width,event.height))
self.mon_image = ImageTk.PhotoImage(self.img)
self.can.create_image(0, 0, image=self.mon_image, anchor=NW)
self.can.tag_lower(fond) #Place l'image sous les autres items
app=Application()
app.root.mainloop() |
Partager