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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| from Tkinter import *
import os
class MyApp():
def __init__(self):
Frame.__init__(self)
Label(text='Code',fg='dark blue').grid(row=0,column=0,sticky=E)
Label(text='Taille',fg='dark blue').grid(row=1,column=0,sticky=E)
Label(text='Extension',fg='dark blue').grid(row=2,column=0,sticky=E)
self.chaine,self.taille,self.extension=StringVar(),IntVar(),StringVar()
self.chaine.set("default")
self.taille.set(100)
self.extension.set("png")
self.entry1=Entry(textvariable=self.chaine)
self.entry2=Entry(textvariable=self.taille)
self.entry3=Entry(textvariable=self.extension)
self.entry1.bind('<Return>',self.check_error)
self.entry2.bind('<Return>',self.check_error)
self.entry3.bind('<Return>',self.check_error)
self.entry1.grid(row=0,column=1,padx=5,pady=5,sticky=W)
self.entry2.grid(row=1,column=1,padx=5,pady=5,sticky=W)
self.entry3.grid(row=2,column=1,padx=5,pady=5,sticky=W)
self.width_max,self.height_max=200,200
def check_error(self,event):
try: self.taille.get()
except: self.error_detected("taille")
else:
if(self.chaine.get() == ""): self.error_detected("chaine")
if(self.extension.get() != "png" \
and self.extension.get() != "jpg"
and self.extension.get() != "jpeg"
and self.extension.get() != "bmp"
and self.extension.get() != "gif"):
self.error_detected("extension")
else:
self.getImage(self.chaine.get(),self.taille.get(),self.extension.get())
def error_detected(self,location):
if(location == "taille"):
self.taille.set(100)
elif(location == "chaine"):
self.chaine.set("default")
elif(location == "extension"):
self.extension.set("png")
else:
return 0
def getImage(self, value, height = 100, extension = "png"):
import Image, ImageFont, ImageDraw, ImageTk
from string import lower, upper
#petit saut en avant, je zappe quelques dizaines de lignes ou fonctions inutiles
photo=ImageTk.PhotoImage(self.im)
self.can=Canvas(width=self.width_max,height=self.height_max,bg='grey')
self.can.grid(row=3,column=0,columnspan=2,padx=5,pady=5)
self.label=Label(image=photo)
self.label.image=photo
self.label.grid(row=3,column=0,columnspan=2,padx=5,pady=5)
Button(text='Save',command=self.save).grid(row=4,column=0)
Button(text='Settings',command=self.settings).grid(row=4,column=1)
Button(text='Export',command=self.export).grid(row=5,column=0)
#autres fonctions,meme syntaxe
if __name__=='__main__':
MyApp().mainloop() |
Partager