Bonjour, je souhaite créer un énonce a trou a propos des identités remarquables (genre QCM).
je n'arrive cependant pas a récupérer les valeurs de mes champs de textes.
Afin de gagner en place, je place les champs de texte à grands coups de for/in, mais cela pose le problème suivant : touts mes champs de saisie ont le même nom (ch1). Cela ne posant pas de problème a l'affichage, je pensais qu'en récupérant les saisies (avec un .get() ) j'aillais avoir une liste, or cela me met une erreur :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\lmd\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
    return self.func(*args)
  File "C:\Users\lmd\Desktop\TIEMEN\# PYTHON\QCM.py", line 128, in valider
    rep = ch1.get()
TypeError: get() missing 1 required positional argument: 'self'
Je pense qu'il faudrait soit trouver le moyen de créer une variable variable, ch(i) pour avoir x champs de saisie différents afin de conserver l'usage des for/in , ou alors une autre méthode de récupération pour avoir une liste.

Je vous joint également l'ensemble du code:
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from tkinter import *
from random import *
fen1=Tk()
can1=Canvas(fen1,width=800,  height=700,bg='white')
can1.pack()
Reponse = []
Visible = []
Type = []
ch1 = StringVar
bou1=Button(text='quitter',command=fen1.destroy)
bou1.place(x=200,y=10) 
 
 
 
def choix(choix):
    global Reponse
    global Visible
    global Type
    if choix == 0:
        t1 = randrange(1,16)
        t2 = randrange(1,16)
        L = [str(t1)+"x",str(t2),str(t1*t1)+"x²",str(2*t1*t2)+"x",str(t2*t2)]
        V = ["  "] *5
        a = 0
        b = 2
        while (a==0 and b == 2) or (a == 1 and b == 4) or (a == b):
            a = randrange(5)
            b = randrange(5)
            if a > b:
                i = b
                b = a
                a = i
        V[a] = L[a]
        V[b] = L[b]
        Reponse.append(L)
        Visible.append(V)
        Type.append("A")
    if choix == 1:
        t1 = randrange(1,16)
        t2 = randrange(1,16)
        L = [str(t1)+"x",str(t2),str(t1*t1)+"x²",str(2*t1*t2)+"x",str(t2*t2)]
        V = ["  "] *5
        a = 0
        b = 2
        while (a==0 and b == 2) or (a == 1 and b == 4) or (a == b):
            a = randrange(5)
            b = randrange(5)
            if a > b:
                i = b
                b = a
                a = i
        V[a] = L[a]
        V[b] = L[b]
        Reponse.append(L)
        Visible.append(V)
        Type.append("B")
    if choix == 2:
        t1 = randrange(1,16)
        t2 = randrange(1,16)
        L = [str(t1)+"x",str(t2),str(t1)+"x",str(t2),str(t1*t1)+"x²",str(t2*t2)]
        V = ["  "] * 6
        a = 0
        b = 2
        c =4
        while (a==0 and b == 2 and c == 4) or (a == 1 and b == 3 and c == 5) or (a == b or a == c or b == c):
            a = randrange(6)
            b = randrange(6)
            c = randrange(6)
            t = [a,b,c]
            t = sorted(t)
            a = t[0]
            b = t[1]
            c = t[2]
        V[a] = L[a]
        V[b] = L[b]
        V[c] = L[c]
        Reponse.append(L)
        Visible.append(V)
        Type.append("C")
 
def affichage():
    global Visible
    y = 30
    r = -1
    for i in Type:
        r += 1
        y += 30
        if i == "A":
            texte=Label(text= "(          +           )² =             +             +             ", font=50)
            texte.place(x=10,y=y-3)
            for i in range(5):
                if Visible[r][i] == "  ":
                    Champ1 = Entry(fen1, textvariable= ch1, bg ='bisque', fg='maroon', width= 4)
                    Champ1.place(x=i*60+20,y=y)
                else:
                    texte1 = Label(text= str(Visible[r][i]), font=50)
                    texte1.place(x=i*60+20,y=y-3)
        if i == "B":
            texte=Label(text= "(           -           )² =              -             +             ", font=50)
            texte.place(x=10,y=y-3)
            for i in range(5):
                if Visible[r][i] == "  ":
                    Champ1 = Entry(fen1, textvariable= ch1, bg ='bisque', fg='maroon', width= 4)
                    Champ1.place(x=i*60+20,y=y)
                else:
                    texte1 = Label(text= str(Visible[r][i]), font=50)
                    texte1.place(x=i*60+20,y=y-3)
        if i == "C":
            texte=Label(text= "(           +           ) (             -           ) =              -           ", font=50)
            texte.place(x=10,y=y-3)
            for i in range(6):
                if Visible[r][i] == "  ":
                    Champ1 = Entry(fen1, textvariable= ch1, bg ='bisque', fg='maroon', width= 4)
                    Champ1.place(x=i*60+20,y=y)
                else:
                    texte1 = Label(text= str(Visible[r][i]), font=50)
                    texte1.place(x=i*60+20,y=y-3)
 
def initialize() :
    for i in range(3):
        a = randrange(3)
        choix(a)
    affichage()
 
 
 
def valider():
    rep = ch1.get()
    print(rep)
 
initialize()
 
bou2=Button(text='valider',command=valider )
bou2.place(x=140,y=10)
bou2=Button(text='nouveau',command=initialize )
bou2.place(x=260,y=10)
 
 
 
 
fen1.mainloop()
Merci de votre aide,
Ti.du.du39