« Programmation Python/Et pour quelques widgets de plus... » : différence entre les versions

Contenu supprimé Contenu ajouté
Ligne 13 :
Lorsque l'utilisateur sélectionne l'un des boutons, la valeur correspondant à ce bouton est affectée à la ''variable Tkinter'' commune.
 
<source lang=python line>
<pre>
from Tkinter import * #1
 
#2
class RadioDemo(Frame): #3
"""Démo : utilisation de widgets 'boutons radio'""" #4
def __init__(self, boss =None): #5
"""Création d'un champ d'entrée avec 4 boutons radio""" #6
Frame.__init__(self) #7
self.pack() #8
# Champ d'entrée contenant un petit texte : #9
self.texte = Entry(self, width =30, font ="Arial 14") #10
self.texte.insert(END, "La programmation, c'est génial") #11
self.texte.pack(padx =8, pady =8) #12
# Nom français et nom technique des quatre styles de police : #13
stylePoliceFr =["Normal", "Gras", "Italique", "Gras/Italique"] #14
stylePoliceTk =["normal", "bold", "italic" , "bold italic"] #15
# Le style actuel est mémorisé dans un 'objet-variable' Tkinter ; #16
self.choixPolice = StringVar() #17
self.choixPolice.set(stylePoliceTk[0]) #18
# Création des quatre 'boutons radio' :
for n in #19range(4):
bout = Radiobutton(self,
for n in range(4): #20
bout = Radiobutton(self, text = #21stylePoliceFr[n],
textvariable = stylePoliceFr[n]self.choixPolice, #22
variablevalue = self.choixPolicestylePoliceTk[n], #23
valuecommand = stylePoliceTk[n], #24self.changePolice)
bout.pack(side =LEFT, padx =5) #26
command = self.changePolice) #25
 
bout.pack(side =LEFT, padx =5) #26
def changePolice(self):
#27
"""Remplacement du style de la police actuelle""" #29
def changePolice(self): #28
police = "Arial 15 " + self.choixPolice.get() #30
"""Remplacement du style de la police actuelle""" #29
self.texte.configure(font =police) #31
police = "Arial 15 " + self.choixPolice.get() #30
 
self.texte.configure(font =police) #31
if __name__ == '__main__':
#32
RadioDemo().mainloop()
if __name__ == '__main__': #33
</source>
RadioDemo().mainloop() #34
</pre>
 
;Commentaires