Bonsoir,

j'ai cette erreur qui s'affiche"UnboundLocalError: local variable 'soust' referenced before assignment" pourtant cette variable est bien defini en globale. Une solution ?







Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from tkinter import *
from PIL import Image, ImageTk
from tkinter.messagebox import *
 
 
tref=[0,36671014,87076785,80614169]
tprix=[0,0.20,0.25,0.10]
soust=[]
tnb=[0,0,0,0]
t=[]
obj=[]
timg=["","chevillefrap.jpg","molly.png","cheville.jpg"]
tproduit=["","Cheville à frapper","Cheville Molly","Cheville",]
st=0.00
dicimg = {}
 
def erreur():
    showerror('Erreur', 'Cette référence est fausse !')
 
 
def valider():
    f=saisi.get()
    g=s.get()
    i=0
    while i<(len(tref)):
        i=i+1
        if int(f) == tref[i]:
            tnb[i]=int(g)
            obj.append(int(f))
            st=tprix[i]*tnb[i]
            soust.append(st)
            t.append(st)
            soust = " Sous Total : %.2f €" % st
            texteLabel1=Label(fen1, text = soust )
            texteLabel1.pack()
            champ_label = Label(fen1, text=tproduit[i])
            champ_label.pack(padx=5, pady=5)
            image=timg[i]
            image = Image.open(image)
            photo = ImageTk.PhotoImage(image)
            dicimg['img1'] = photo
            canvas.create_image(350, 300, image=photo)
 
        if int(f)!=(len(tref)):
                erreur()
def prixtotal():
    fen2=Tk()
 
    l = LabelFrame(fen2, text="Prix Total", padx=20, pady=20)
    l.pack(fill="both", expand="yes")
    pt=sum(t)
    Label(l,text="Liste Objets").pack()
 
    Label(l,text=" Prix Total : %.2f €" % pt).pack()
    Label(l, text=" Prix Total : %.2f €" % pt,side=RIGHT).pack()
 
fen1=Tk()
fen1.configure(width=700,height=700)
fen1.title('Easy Commande')
 
 
canvas = Canvas(fen1,width=700, height=700, bg='white')
canvas.pack(side=LEFT, padx=5, pady=5)
 
 
texteLabel1=Label(fen1, text = "Entrez la référence :")
texteLabel1.pack()
 
 
 
saisi=Entry(fen1)
saisi.pack(padx =3, pady =5)
 
 
 
 
s = Spinbox(fen1, from_=1, to=99999999999)
s.pack()
 
bouton1=Button(fen1, text="Valider", command=valider)
bouton1.pack()
 
bouton2=Button(fen1, text="Annuler", command=fen1.destroy)
bouton2.pack()
 
bouton3=Button(fen1, text="Prix Panier", command=prixtotal)
bouton3.pack(side=RIGHT)
 
fen1.mainloop()