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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| # -*- coding: cp1252 -*-
import Tkinter as tk
import Image
import tkFont
from tkColorChooser import askcolor
class ajouttexte:
def __init__(self):
self.Dic_TXT=[]
self.texte='Your Texte'
self.size=36
self.familly="Helvetica"
self.style='normal'
self.color='black'
self.root=tk.Tk()
self.root.title('création de texte')
self.canvas=tk.Canvas(self.root,width=500,height=500,bg='white')
self.canvas.grid()
self.canvas.bind('<Button-1>',self.crea)
#attribut=tk.Button(self.root,text='couleur',command=self.setBgColor)
#attribut.grid()
quitter=tk.Button(self.root,text='quitter',command=self.root.quit)
quitter.grid()
self.root.mainloop()
self.root.destroy()
def setBgColor(self):
(triple, hexstr) = askcolor()
if hexstr:
self.color= hexstr
self.champcolor.delete(0,tk.END)
self.champcolor.insert(0,self.color)
self.applychange(event=tk.NONE)
def crea(self,event):
self.font=tkFont.Font(family=(self.familly),size=(self.size),weight=(self.style))
self.txt=self.canvas.create_text(event.x,event.y,fill=self.color,text=self.texte,font=self.font)
self.Dic_TXT.append([self.txt,event.x,event.y,self.texte,self.familly,self.style,self.size])
self.x,self.y=event.x,event.y
print self.Dic_TXT
self.modiftextpan()
def modiftextpan(self):
self.top=tk.Toplevel()
self.top.title('Attributs de texte')
self.attribut()
#tk.Button(frametop,width=64,text='Fermer',command=self.top.destroy).grid()
def attribut(self):
frametop=tk.Frame(self.top)
frametop.grid()
tk.Label(frametop,text='ID texte').grid(column=0,row=0,padx=3,pady=3)
self.id=tk.Label(frametop,width=20,text=self.txt)
self.id.grid(column=1,row=0)
tk.Label(frametop,text='Texte').grid(column=0,row=1,padx=3,pady=3)
self.champtxt=tk.Entry(frametop,width=50)
self.champtxt.bind('<FocusOut>',self.applychange)
self.champtxt.bind('<FocusIn>',self.seltxt)
self.champtxt.bind('<Return>',self.applychange)
self.champtxt.grid(column=1,row=1,columnspan=3,padx=3,pady=3)
self.champtxt.insert(0,self.texte)
tk.Label(frametop,text='Police').grid(column=0,row=2,padx=3,pady=3)
self.champfont=tk.Entry(frametop)
self.champfont.bind('<FocusOut>',self.applychange)
self.champfont.bind('<FocusIn>',self.seltxt)
self.champfont.bind('<Return>',self.applychange)
self.champfont.grid(column=1,row=2,padx=3,pady=3)
self.champfont.insert(0,self.familly)
tk.Label(frametop,text='Taille').grid(column=2,row=2,padx=3,pady=3)
self.champtaille=tk.Entry(frametop)
self.champtaille.bind('<FocusOut>',self.applychange)
self.champtaille.bind('<FocusIn>',self.seltxt)
self.champtaille.bind('<Return>',self.applychange)
self.champtaille.grid(column=3,row=2,padx=3,pady=3)
self.champtaille.insert(0,self.size)
tk.Label(frametop,text='Style').grid(column=0,row=3,padx=3,pady=3)
self.champstl=tk.Entry(frametop)
self.champstl.bind('<FocusOut>',self.applychange)
self.champstl.bind('<FocusIn>',self.seltxt)
self.champstl.bind('<Return>',self.applychange)
self.champstl.grid(column=1,row=3,padx=3,pady=3)
self.champstl.insert(0,self.style)
tk.Label(frametop,text='Couleur').grid(column=2,row=3,padx=3,pady=3)
self.champcolor=tk.Entry(frametop)
self.champcolor.bind('<FocusOut>',self.applychange)
self.champcolor.bind('<FocusIn>',self.seltxt)
self.champcolor.bind('<Return>',self.applychange)
self.champcolor.grid(column=3,row=3,padx=3,pady=3)
self.champcolor.insert(0,self.color)
tk.Button(frametop,text='...',width=2,command=self.setBgColor).grid(column=4,row=3,padx=3,pady=3)
def seltxt(self,event):
self.txt=int(self.id.cget("text"))
print self.txt
def applychange(self,event):
print self.champtaille.get()*(-1)
self.font=tkFont.Font(family=(self.champfont.get()),size=(int(self.champtaille.get())*(-1)),
weight=(self.champstl.get()))
self.canvas.delete(self.txt)
for i in self.Dic_TXT:
if i[0]==self.txt:
self.txt=i[0]
self.Dic_TXT.remove(i)
else:
pass
self.canvas.find_withtag(self.id)
self.txt=self.canvas.create_text(self.x,self.y,fill=(self.champcolor.get()),
text=(self.champtxt.get()),font=self.font)
self.Dic_TXT.append([self.txt,self.x,self.y,(self.champtxt.get()),
(self.champfont.get()),(self.champstl.get()),(self.champtaille.get())])
self.id.configure(text=self.txt)
print self.Dic_TXT
if __name__ == "__main__":
app=ajouttexte() |
Partager