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
| 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, bd=0, 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=12, bg="beige", padx=50)#, relief=SUNKEN)
t = "mon lab"
monText = Text(frame)
newBtn = Button(toolbar, text="Tableau", bg="maroon", fg="white", borderwidth=3, command=para1)
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')
if __name__ == '__main__':
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=12, background='orange', font=('Tempus Sans ITC', 12, 'bold'))
text.pack(fill=Y)
t="jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj"
text.insert(0.0, t)
root.update()
para2(Tk)
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=12, background='orange', font=('Tempus Sans ITC', 12, 'bold'))
text.pack(fill=Y)
t="kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
text.insert(0.0, t)
root.update()
root = Tk()
color= "lightyellow"
root.title("Syntax Analyser")
myWidth = 25 #largeur des boutons du menu
myHeight = 25 #hauteur des boutons du menu
myColor="lightblue"
toolbar = Frame(root, borderwidth=2, 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=1)
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.configure(background="green")
root.mainloop() |
Partager