Hello ,
I'm working to build a programme that connects to MySQL database using Tkinter .In a step , i wanted to create dynamicly a number of entries widgets ( here : tailles_entry[i] ) depending on the number of elements of a list ( here liste1 ) . I could create that entries ( function : valider() ), but i couldn't insert the texts entered into the database ( function valider1() ) .
I show here all the code of the window :
def Interface2() :
global interf2
interf2 = Tk()
interf2.geometry("500x400")
interf2.title(' Gestion du Depot ')
f1 = Frame(interf2, bg="blue", width=500, height=700)
f1.pack( fill=X, expand=0)
lab2 = Label(interf2, text="Veuillez saisir le numero d'Import du Model ( num+année , ex: 122013 )\n et cliquer sur valider " , bg = "blue", fg = "white" )
lab2.place ( x=80 , y=45 )
global liste1
global distligne
global modelidvar
global numbonvar
global qtetaillevar
modelidvar = StringVar()
numbonvar = StringVar()
qtetaillevar = StringVar()
qtetaillevar = {}
distligne = 0
liste1 = []
lab3= Label(interf2, text="Référence Model :" , bg = "blue", fg = "white" )
lab3.place ( x=30 , y=100)
modelid_entry = ttk.Entry(interf2, width=13, textvariable=modelidvar)
modelid_entry.place (x = 140 , y = 100 )
tailles_entry = ttk.Entry(interf2, width=13)
def revenir():
interf2.destroy()
InterfaceDeps()
def valider1():
print "valider1"
connect()
curs = conn.cursor()
curs.execute(' select client.*, model.* from client,model where client.clientid=model.client AND modelid=%s ;'%modelidvar)
row = curs.fetchall()
if row :
liste1 = row[0][12].split(",")
print liste1
print liste1
i = 0
while i < len(liste1) :
#for i in range(len(liste1)):
print tailles_entry[i].get()
i = i + 1
#qtetaillevar[i] = str(qtetaillevar[i])
#print "qtetaillevar[%s]"%i
def valider():
global distligne
qtetaillevar = {}
distligne = 0
modelidvar = modelid_entry.get()
connect()
curs = conn.cursor()
curs.execute("UPDATE model SET operation='Lavage' WHERE modelid=%s"%modelidvar)
curs.execute(' select client.*, model.* from client,model where client.clientid=model.client AND modelid=%s ;'%modelidvar)
row = curs.fetchall()
if row :
liste1 = row[0][12].split(",")
print liste1
print liste1[0]
print liste1[1]
print len(liste1)
#for i in range(len(liste1)):
i=0
while i < len(liste1) :
qtetaillevar[i] = StringVar()
distligne = 30 + distligne
label100 = Label(interf2 , text="Quantité/%s"%(liste1[i]) , justify=LEFT, bg = "blue", fg = "white" ).place(x=30 , y=165+distligne)
tailles_entry[i] = ttk.Entry(interf2, width=13, textvariable=qtetaillevar[i]).place (x = 130 , y = 165+distligne)
i = i +1
lab2.config(text="Veuillez saisir les données du Model : %s"%row[0][4] ,font=("times",10,"bold"), bg = "blue")
lab2.place( x = 110 , y = 135 )
lab3.place ( x=15 , y=30)
lab31= Label(interf2, text="%s"%row[0][3] ,font=("times",10,"bold"), bg = "blue", fg = "red" )
lab31.place ( x=105 , y=30)
lab4= Label(interf2, text="Client :" , bg = "blue", fg = "white" )
lab4.place ( x=202 , y=30)
lab41= Label(interf2, text="%s"%row[0][1] ,font=("times",10,"bold"), bg = "blue", fg = "red" )
lab41.place ( x=238 , y=30)
lab5= Label(interf2, text="Atelier :" , bg = "blue", fg = "white" )
lab5.place ( x=370 , y=30)
lab51= Label(interf2, text="%s"%row[0][2] ,font=("times",10,"bold"), bg = "blue", fg = "red" )
lab51.place ( x=429 , y=30)
lab6= Label(interf2, text="Matricule Model :" , bg = "blue", fg = "white" )
lab6.place ( x=15 , y=60)
lab61= Label(interf2, text="%s"%row[0][4] ,font=("times",10,"bold"), bg = "blue", fg = "red" )
lab61.place ( x=105 , y=60)
lab7= Label(interf2, text="Opération :" , bg = "blue", fg = "white" )
lab7.place ( x=370 , y=60)
lab71= Label(interf2, text="%s"%row[0][10] ,font=("times",10,"bold"), bg = "blue", fg = "red" )
lab71.place ( x=429, y=60)
lab7= Label(interf2, text="Quantité demandée :" , bg = "blue", fg = "white" )
lab7.place ( x=202 , y=60)
lab71= Label(interf2, text="%s"%row[0][9] ,font=("times",10,"bold"), bg = "blue", fg = "red" )
lab71.place ( x=307 , y=60)
lab8= Label(interf2, text="Numero de BON :" , bg = "blue", fg = "white" )
lab8.place ( x=30 , y=165)
numbon_entry = ttk.Entry(interf2, width=13, textvariable=numbonvar)
numbon_entry.place (x = 130 , y = 165)
valider.config(command = valider1)
valider.place(x=350 , y=200)
#valider.place_forget()
modelid_entry.place_forget()
print row[0][1]
valider = Button(interf2, text = " Valider ", command = valider)
valider.place( x=250, y=100)
revenir = Button(interf2, text = " revenir ", command = revenir)
revenir.place( x=12, y=300)
Quitter = Button(interf2, text = "Quitter" , command = interf2.destroy)
Quitter.place( x=230, y=350 )
interf2.after(0,center,interf2)
interf2.mainloop()
After clicking on "valider1" button i got this error message :
OperationalError: (1054, "Unknown column 'PY_VAR4' in 'where clause'")