Modifications

Sauter à la navigation Sauter à la recherche
260 octets ajoutés ,  11 août 2016 à 10:45
Ligne 43 : Ligne 43 :     
== Définition de l'interface ==
 
== Définition de l'interface ==
{{traduction}}
+
La structure {{fname|touch_buttons}} fait correspondre (''map'' en anglais) le texte des bouton et la position du centre (x,y avec le coin supérieur gauche à 0,0) de ce texte sur l'afficheur. Nous bouclons ensuite dans cette structure pour dessiner chacun de ces "boutons".
 
  −
The {{fname|touch_buttons}} map simply holds the button text and center position (x,y with top left as 0,0) for this text on the display. We then loop through this map and draw each "button".
      
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 +
# Declarer un dictionnaire
 
touch_buttons = {'17 on':(80,60), '4 on':(240,60), '17 off':(80,180), '4 off':(240,180)}
 
touch_buttons = {'17 on':(80,60), '4 on':(240,60), '17 off':(80,180), '4 off':(240,180)}
 
   
 
   
 +
# Obtenir la clé (k) et la valeur (v) pour chacun des elements du dictionnaire
 +
# k contient le libellé du bouton et v la position du texte
 
for k,v in touch_buttons.items():
 
for k,v in touch_buttons.items():
 
     text_surface = font_big.render('%s'%k, True, WHITE)
 
     text_surface = font_big.render('%s'%k, True, WHITE)
 
     rect = text_surface.get_rect(center=v)
 
     rect = text_surface.get_rect(center=v)
 
     lcd.blit(text_surface, rect)
 
     lcd.blit(text_surface, rect)
+
 
 +
# Rafraichir l'affichage
 
pygame.display.update()
 
pygame.display.update()
 
</syntaxhighlight>
 
</syntaxhighlight>
29 918

modifications

Menu de navigation