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
|
from tkinter import *
from tkinter import ttk
master = Tk()
L = master.winfo_screenwidth()
H = master.winfo_screenheight()
bout=[]
master.minsize(L,H)
#master.geometry("320x600")
motsManquants=[]
class MyButton(Button):
def on_click(self):
for k in range(1,3) :
largMax = 300#int(b.winfo_width())
fin=0
maLargTot=0
while fin==0:#maLargTot<largMax :
maLargTot=0
for el in bout : # on récupère le padx du premier élément et la largeur de la totalité des boutons sur toute la ligne
#print(el[0])
if el[1]==k :
myPad0 = str(el[0].cget("padx"))
myPadx=int(myPad0)+1
maLargTot=maLargTot+el[0].winfo_reqwidth()
#print("myPad0 = " +str(myPadx))
for el in bout :
if el[1]==k and maLargTot<largMax :
#print(str(el[1])+ ":" +str(k))
maLargTot=maLargTot-el[0].winfo_reqwidth()
el[0].config(padx=myPadx)
maLargTot=maLargTot+el[0].winfo_reqwidth()
#print("maLargTot = " +str(maLargTot))
#print("largMax = " +str(largMax))
#print("k = " +str(k))
#print(str(el[0].winfo_reqwidth()))
#print("maLargTot1 = " +str(maLargTot))
#print(str(el[2]))
elif el[1]==k and maLargTot>=largMax :
#print(str(el[1])+ ":" +str(k))
#print("maLargTot = " +str(maLargTot))
#print("largMax = " +str(largMax))
#print(" Bouton N° "+str(el[5])+ " : " + str(el[0].winfo_reqwidth()))
#print("k = " +str(k))
fin=1
break
def callback() :
conteneur = Frame(master, bg='yellow')
conteneur.pack()
x = 0
pack = True
i = 0
j = 0
n = 0
texte = [("HG","Et","GN,","AP","FC"),("MB","je","GN,","AP","FC"),("OJ","me","GN,","AP","FC"),("KI","suis","GN,","AP","FC"),("OR","demandé","GN,","AP","FC")]
for mot2 in texte :
n = n+1
mot00 = mot2[3]
mot01 = mot2[4]
if mot00 == "AP" and mot01 == "FC":
mot = mot2[1]
if not x :
frame = Frame(conteneur, bg='grey', width=master.winfo_screenwidth(), height=30)
frame.pack()
x=1
i += 1
# On ne définit pas le parent
w = MyButton(text=mot, textvariable=str(n), font='arial 16', fg="black", bg="yellow")#, command=lambda j=n: OnButton2Click(j))
w['command'] = w.on_click
w.pack(in_=frame, side='left')
w1=(w, n, mot)
bout.append(w1)
b = Button(master, text="OK", width=120, command=callback)
b.pack()
mainloop() |
Partager