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
|
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.'
)
class VerticalScrolledFrame(Frame):
"""A pure Tkinter scrollable frame that actually works!
* Use the 'interior' attribute to place widgets inside the scrollable frame
* Construct and pack/place/grid normally
* This frame only allows vertical scrolling
"""
def __init__(self, parent, *args, **kw):
Frame.__init__(self, parent, *args, **kw)
# create a canvas object and a vertical scrollbar for scrolling it
vscrollbar = Scrollbar(self, orient=VERTICAL)
vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
canvas = Canvas(self, bd=0, highlightthickness=0, bg="orange", yscrollcommand=vscrollbar.set)
canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
vscrollbar.config(command=canvas.yview)
# reset the view
canvas.xview_moveto(0)
canvas.yview_moveto(0)
# create a frame inside the canvas which will be scrolled with it
self.interior = interior = Frame(canvas, bg="green")
interior_id = canvas.create_window(0, 0, window=interior, anchor=NW)
# track changes to the canvas and frame width and sync them,
# also updating the scrollbar
def _configure_interior(event):
# update the scrollbars to match the size of the inner frame
size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
canvas.config(scrollregion="0 0 %s %s" % size)
if interior.winfo_reqwidth() != canvas.winfo_width():
# update the canvas's width to fit the inner frame
canvas.config(width=interior.winfo_reqwidth())
interior.bind('<Configure>', _configure_interior)
def _configure_canvas(event):
if interior.winfo_reqwidth() != canvas.winfo_width():
# update the inner frame's width to fill the canvas
canvas.itemconfigure(interior_id, width=canvas.winfo_width())
canvas.bind('<Configure>', _configure_canvas)
def callback() :
TabMotsParPhrases1()
if __name__ == '__main__':
def __init__(self, *args, **kwargs):
for w in frame1.winfo_children():
w.destroy()
class TabMotsParPhrases1(Tk):
def __init__(self, *args, **kwargs):
self.frame = VerticalScrolledFrame(master)
self.frame.pack(fill=BOTH, expand=TRUE)
i = 0
fonts = {'normal': 'arial 12','bold': 'arial 9 bold',}
j = 0
for mot in texte.split(' ') :
color = ['yellow', 'orange'][i % 2]
# Traiter la ligne et ainsi de suite ...
data2 = mot
color2="white"
myLabel = Label(self.frame.interior, text=mot, borderwidth=5, relief="sunken", fg="black", bg=color, font=fonts['normal'])#, width=taille)#anchor='ws', int(L/nbreElement)) #,
myLabel.grid(row=i, column=j, padx=10, pady=10, sticky='ns') #, columnspan=29, padx=1)
j= j+1
#print("j= "+str(j))
self.frame.update()
pL = myLabel.winfo_rootx()+ myLabel.winfo_width()+10+8
tR = master.winfo_width()
print(pL)
print(tR)
#print(master.winfo_rootx())
#print("j = "+str(j))
if pL>tR :#j>5 :
#print(pL)
print("Hey")
j=0
i = i+1
b = Button(master, text="OK", command=callback)
b.pack()
mainloop() |
Partager