| 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
 
 | from Tkinter import *
from random import randint
 
def tafonction():
    # juste pour simuler ta fonction : creation de x, y aleatoire avec randint
    x = randint(0, 800)
    y = randint(0, 600)
    return x, y
 
def Traitement():
 
    listepoint = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T')
 
    for point in listepoint:
        # Sauvegarde des points precedents
        try:
            if x: # Si x existe deja : donc pas le premier point
                ancienx = x # On garde les x, y
                ancieny = y # du point precedent
        except:
            pass # Sinon c'est le premier point
 
        x, y = tafonction() # Recuperation des nouveaux x, y suivant la fonction tafonction()
 
        # On trace les lignes
        try:
            if ancienx:
                # Si ce n'est pas le premier point on trace une ligne
                cv.create_line((ancienx, ancieny),(x,y))
                # Mise en place du texte au dessu ou en dessou suivant if ancieny > y
                if ancieny > y:
                    cv.create_text(x, y-10 , text=listepoint[listepoint.index(point)-1] + point)
                else:
                    cv.create_text(x, y+10 , text=listepoint[listepoint.index(point)-1] + point)
                    print listepoint(listepoint.index(point)-1) + point
        except:
            pass # C'est le premier point
 
# Interface
master = Tk()
cv = Canvas(master, width=800, height=600)
cv.pack()
Button(master, text="Quitter", command = master.destroy).pack()
Traitement()
mainloop() |