| 12
 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
 
 | import tkinter as tk
 
mot = "PUxLL" # mot à écrire
larg = 10   # largeur des segments
prof = 10   # profondeur de la pointe d'un segment
haut_y = 60   # longueur totale d'un segment vertical
haut_x = 60   # longueur totale d'un segment horizontal
 
nb_let = len(mot)       # nombre de lettres dans le LCD: ici, ajusté au mot
#nb_let = 15             # pour tout tester (toutes les lettres)
sep_let = 10+2*larg     # espace entre lettres
x_pan, y_pan = 15, 15   # espace entre lettres et bord du LCD
 
# caractéristiques d'un segment (vertical ou horizontal)
# les deux segments sont définis pour pouvoir les modifier séparément
lst_seg_v = [(0, 0), (larg/2, prof), (larg/2, haut_y-prof),
             (0, haut_y), (-larg/2, haut_y-prof), (-larg/2, prof)]
lst_seg_h = [(0, 0), (prof, larg/2), (haut_x-prof, larg/2),
             (haut_x, 0), (haut_x-prof, -larg/2), (prof, -larg/2)]
 
# segments possibles 0->2 horizontaux, 3->7 verticaux
lst_seg_tot = [(0, 0, False), (0, haut_y, False), (0, haut_y*2, False),
               (0, 0, True), (0, haut_y, True), (haut_x, 0, True), (haut_x, haut_y, True)]
 
# description des lettres
description = {'L' : [3, 4, 2], 'P' : [0, 3, 5, 1, 4], 'U' : [3, 4, 5, 6, 2],
               'D' : [0, 5, 3, 4, 6, 2], 'E' : [0, 3, 2, 1, 4], 'I' : [3, 4],
               'S' : [3, 1, 0, 6, 2], "B" : [0, 1, 2, 3, 4, 5, 6], "_" : [2],
               'C' : [0, 3, 4, 2], 'R' : [0, 6, 3, 5, 1, 4], 'H' : [6, 3, 4, 1, 5],
               'T' : [0, 3, 4], 'N' : [6, 3, 4, 1], 'G' : [0, 3, 4, 2, 6, 1]}
 
# fenetre
app = tk.Tk()
# le canvas est ajusté au nombre de lettres
can = tk.Canvas(app, height = (haut_y+y_pan)*2,
                width = (haut_x*nb_let+sep_let*(nb_let-1)+ x_pan*2))
can.pack()
 
def affiche_seg(x, y, v=True):
    """Affichage d'un segment à partir du point (x, y).
    v=True pour vertical/False pour horizontal"""
    pts = [(x+x1, y+y1) for x1, y1 in (lst_seg_v if v else lst_seg_h)]
    can.create_polygon(*pts, fill = "red")
 
#mot = "".join(description.keys())     # test de toutes les lettres possibles
pos_let = 0     # position de la lettre horizontalement (dans la phrase)
for lett in mot:
    if lett not in description.keys():      # pour éviter les lettres non définies
        lett = "_"
    for seg in description[lett]:
        x, y, v = lst_seg_tot[seg]
        affiche_seg(x+x_pan+pos_let*(haut_x+sep_let), y+y_pan, v)
    pos_let += 1
 
app.mainloop() | 
Partager