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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| from tkinter import *
from tkinter import ttk
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, borderwidth=10, highlightthickness=0, bg="black", 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="beige")
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 create_frame1(master, t):
L = root.winfo_screenwidth()
H = root.winfo_screenheight()
frame = Frame(master, bd=0, bg="beige", padx=50, pady=30)#, relief=SUNKEN)
t = "mon lab"
monText = Text(frame)
newBtn = Button(toolbar, text="Tableau", bg="maroon", fg="white", borderwidth=0, command=mesParas)
newBtn.pack(side=LEFT, fill=X)
#root.geometry("%dx%d%+d%+d" % (L,H,0,0))
root.update_idletasks()
print(root.winfo_width())
print("ok")
print(frame.winfo_width())
return frame
def ChangeColor():
newBtn3.configure(bg='red')
def mesParas ():
para0(Tk)
para3(Tk)
if __name__ == '__main__':
class para0(Tk):
def __init__(self, *args, **kwargs):
for w in frame1.winfo_children():
w.destroy()
#self.frame = VerticalScrolledFrame(frame1)
#self.frame.pack(fill=BOTH, expand=TRUE)
text = Text(frame1)#, yscrollcommand=yscrollbar.set)
text.tag_configure('color', underline="1", borderwidth=0, background='orange', font=('Tempus Sans ITC', 12, 'bold'))
text.pack(fill=BOTH)
t="kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
text.insert(0.0, t)
root.update()
class para3(Tk):
def __init__(self, *args, **kwargs):
#self.frame = VerticalScrolledFrame(frame1)
#self.frame.pack(fill=BOTH, expand=TRUE)
text = Text(frame1)#, yscrollcommand=yscrollbar.set)
text.tag_configure('color', underline="1", borderwidth=0, background='orange', font=('Tempus Sans ITC', 12, 'bold'))
text.pack(fill=BOTH)
t="kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
text.insert(0.0, t)
root.update()
class para1(Tk):
def __init__(self, *args, **kwargs):
for w in frame1.winfo_children():
w.destroy()
self.frame = VerticalScrolledFrame(frame1)
self.frame.pack(fill=BOTH, expand=TRUE)
text = Text(self.frame.interior)#, yscrollcommand=yscrollbar.set)
text.tag_configure('color', underline="1", borderwidth=0, background='orange', font=('Tempus Sans ITC', 12, 'bold'))
text.pack(fill=BOTH)
t="jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj"
text.insert(0.0, t)
root.update()
class para2(Tk):
def __init__(self, *args, **kwargs):
self.frame = VerticalScrolledFrame(frame1)
self.frame.pack(fill=BOTH, expand=TRUE)
text = Text(self.frame.interior)#, yscrollcommand=yscrollbar.set)
text.tag_configure('color', underline="1", borderwidth=0, background='orange', font=('Tempus Sans ITC', 12, 'bold'))
text.pack(fill=BOTH)
t="kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
text.insert(0.0, t)
root.update()
root = Tk()
color= "lightyellow"
root.title("Syntax Analyser")
myColor="lightblue"
toolbar = Frame(root, borderwidth=0, relief='raised', background=myColor)
toolbar.pack(side=TOP, fill=X)
nb = ttk.Notebook(root)
# Defines and places the notebook widget
root.update()
numero=1
frame1 = create_frame1(nb, numero)
nb.add(frame1, text='Texte')
ttk.Style().configure(root, background=color)
nb.pack(fill=BOTH, expand=0)
L = root.winfo_screenwidth()
H = root.winfo_screenheight()
#root.geometry('{}x{}'.format(L, H))
root.geometry("%dx%d%+d%+d" % (L,H,0,0))
root.title("Close Test")
root.configure(background="green")
root.mainloop() |
Partager