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
| from tkinter import *
master = Tk()
L = master.winfo_screenwidth()
H = master.winfo_screenheight()
master.minsize(L,H)
#master.geometry("320x600")
texte = (
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed doeiusmod '
'tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim '
'veniam, quis nostrud exercitation ullamco laboris nisi utaliquip ex ea '
'commodo consequat. Duis aute irure dolor inreprehenderit in voluptate '
'velit esse cillum dolore eu fugiat nullapariatur. Excepteur sint occaecat '
'cupidatat non proident, sunt inculpa qui officia deserunt mollit anim id '
'est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed '
'doeiusmod tempor incididunt ut labore et dolore magna aliqua.'
)
def callback() :
conteneur = Frame(master, bg='yellow')
conteneur.pack()
x = 0
pack = True
i = 0
bg = ('red', 'pink')
for mot in texte.split(' ') :
if not pack or not x :
frame = Frame(conteneur, bg=bg[i%2], width=320, height=30)
frame.pack()
frame.pack_propagate(False)
i += 1
if not pack :
x = larg
pack = True
try :
# On pack en définissant le parent
bout.pack(in_=frame, side='left')
except :
pass
# On ne définit pas le parent
bout = Button(text=mot)
larg = bout.winfo_reqwidth()
if x + larg > 320 :
pack = False
else :
x += larg
b = Button(master, text="OK", command=callback)
b.pack()
mainloop() |
Partager