1

Is there any way to dynamically resize a widget's size while resizing a window in tkinter ?

Here's the code:

from tkinter import *

root = Tk()
root.geometry("777x575")

text = Text(root , width = 75 , height = 25)
text.grid(row = 0 , column = 0)

scrollbar = Scrollbar(root , command = text.yview)
scrollbar.grid(row = 0 , column = 1 , sticky = N+S+E+W)

text.config(yscrollcommand = scrollbar.set)

button = Button(root , text = "Sample Button")
button.grid(row = 1 , column = 0 , pady = 20)

mainloop()

when I resize my window, the width and height of the widgets stay the same.

what I want is to dynamically resize the widget's inside my window according to the window's size.

Is there any way to achieve this in tkinter ?

It would be great if anyone could help me out.

Lenovo 360
  • 569
  • 1
  • 7
  • 27

1 Answers1

1

Try this raw source code example:

from tkinter import *

root = Tk()
root.geometry("777x575")
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=2)

root.rowconfigure(0, weight=1)

text = Text(root, width = 95 , height = 95)
text.grid(column=0, row=0, ipadx=500, ipady=10, sticky="NSEW")

scrollbar = Scrollbar(text, orient=VERTICAL)
scrollbar.pack(fill=Y, side=RIGHT)

button = Button(root, text = "Sample Button")
button.grid(column=0, row=1, ipadx=500, ipady=10, sticky="NSEW")

mainloop()