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
| #!/usr/bin/python
# -*- coding: utf-8 -*-
from Tkinter import *
from os import linesep
ListeAccents = {' ':'_','é':'e','è':'e','ê':'e','ë':'e','æ':'ae','ã':'a','ä':'a','á':'a','à':'a','â':'a','ä':'a','ù':'','ô':'o','ö':'o','ç':'c','ï':'i','û':'','î':'i','ñ':'n','À':'A','Á':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'AE','Ç':'C','È':'E','É':'E','Ê':'E','Ë':'E','Ñ':'N','Ì':'I','Í':'I','Î':'I','Ï':'I','Ï':'I','Ò':'O','Ó':'O','Ô':'O','Õ':'O','Ö':'O','Ü':'','Û':'','Ú':'','Ù':'','':'OE','':'oe'}
# pas le dict pour ce code mais un copier/coller c'est plus facile
class MonAppli_Globals():
EntryChoixRep_StringVar = None # Je l'utilise aprés
class mon_app(Tk):
def C_Ok(self):
print 'la suite'
def C_Quit(self):
self.destroy()
def quelletouche(self, event):
self.touche=event
def veriftouche(self):
if (self.touche.char not in ListeAccents.keys()) or (self.touche.keysym == "BackSpace"):
return True
else:
self.EntryChoixRep.event_generate(ListeAccents[self.touche.char])
self.EntryChoixRep.configure(validate='key',validatecommand=self.veriftouche)
return False
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self, event = None):
self.geometry("%dx%d+%d+%d" % (230,130, (self.winfo_screenwidth()-230)/2, (self.winfo_screenheight()-130)/2 ) )
self.resizable(False,False)
Label(self, fg="dark slate blue", text= linesep + "Texte à vérifier :").pack(side=TOP)
MonAppli_Globals.EntryChoixRep_StringVar = StringVar()
self.EntryChoixRep = Entry(self, bg="white", fg="dark slate blue", justify = "center", textvariable= MonAppli_Globals.EntryChoixRep_StringVar)
self.EntryChoixRep.pack(side=TOP, pady=10)
self.EntryChoixRep.configure(validate='key',validatecommand=self.veriftouche)
self.EntryChoixRep.bind("<Key>", self.quelletouche)
Frame(self, height=2, bd=1, relief=SUNKEN).pack(side=TOP, fill=X, padx=5, pady=5)
Button(self, text="Valider", fg='dark slate blue', activebackground='white', activeforeground='#2a7aff', command = self.C_Ok).pack(side=LEFT, padx=10)
Button(self, text="Annuler", fg='dark slate blue', activebackground='white', activeforeground='#2a7aff', command = self.C_Quit).pack(side=RIGHT, padx=10)
self.EntryChoixRep.focus_set()
self.bind('<Escape>', self.C_Quit )
if __name__ == "__main__":
app = mon_app(None)
app.mainloop() |