Reputation: 41
I am new in Python. I create vertical and horizontal scroll bar with the help of a post. When I resize the toplevel window then scrollbar does't move. How to make scroll bar move with resizing window. Thanks
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import *
root = Tk()
top=Toplevel(root)
text = Text(top)
vs = Scrollbar(top, orient="vertical")
hs = Scrollbar(top, orient="horizontal")
sizegrip = ttk.Sizegrip(root)
# hook up the scrollbars to the text widget
text.configure(yscrollcommand=vs.set, xscrollcommand=hs.set, wrap="none")
vs.configure(command=text.yview)
hs.configure(command=text.xview)
# grid everything on-screen
text.grid(row=0,column=0,sticky="news")
vs.grid(row=0,column=1,sticky="ns")
hs.grid(row=1,column=0,sticky="news")
sizegrip.grid(row=1,column=1,sticky="news")
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
def fill():
for n in range(30):
text.insert("end", 'check scroll bar ' * 20, "", "\n")
Button(root, text='press', command=fill).grid(row=0, column=0)
root.mainloop()
Upvotes: 2
Views: 1326
Reputation: 7176
You need to tell the Toplevel to adjust the cell in row=0, column=0 when the window is resized:
# grid everything on-screen
top.columnconfigure(0, weight=1)
top.rowconfigure(0, weight=1)
Upvotes: 1