from tkinter import ttk
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("550x240") # width and height of window
my_w.title("www.plus2net.com") # title
my_w.rowconfigure(1,weight=1)
my_w.rowconfigure(2,weight=4)
my_w.columnconfigure(1,weight=1)
s = ttk.Style()
s.configure('TSizegrip', background='red')
font1=['Times',22,'normal'] # font family , size and style
lb1=tk.Label(my_w,text=' Sizegrip for resizing the window ',
height=3, bg='yellow',font=font1)
lb1.grid(row=1,column=1,padx=20,pady=20)
sizegrip = ttk.Sizegrip(my_w)
sizegrip.grid(row=2,column=1,sticky='se')
my_w.mainloop() # Keep the window open
How to align Sizegrip at bottom right in Pack Layout
from tkinter import ttk
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("550x240") # width and height of window
my_w.title("www.plus2net.com") # title
s = ttk.Style()
s.configure('TSizegrip', background='red')
font1=['Times',22,'normal'] # font family , size and style
lb1=tk.Label(my_w,text=' Sizegrip for resizing the window ',
height=3, bg='yellow',font=font1)
lb1.place(x=20,y=10)
sizegrip = ttk.Sizegrip(my_w)
sizegrip.place(x=530,y=220)
my_w.mainloop() # Keep the window open
As we are resizing the window it is better to use relative x, y Positioning.
my_w.resizable(width=0,height=0) # No resize
#my_w.resizable(width=1,height=0) # Only width resize is allowed
#my_w.resizable(width=0,height=1) # Only height resize is allowed
#my_w.resizable(width=1,height=1) # Both height and width resize is allowed ( default )
Here is complete code.
import tkinter as tk
from tkinter import ttk
# Creating the main window
my_w = tk.Tk()
my_w.geometry('300x200')
my_w.resizable(width=0,height=0) # No resize of window
#my_w.resizable(width=1,height=0) # Only width resize is allowed
#my_w.resizable(width=0,height=1) # Only height resize is allowed
#my_w.resizable(width=1,height=1) # Both height and width resize is allowed ( default )
s = ttk.Style()
s.configure('TSizegrip', background='red')
# Adding the Sizegrip widget
sizegrip = ttk.Sizegrip(my_w)
sizegrip.pack(side='bottom',anchor='se')
my_w.mainloop()
Positioning the ttk Sizegrip widget
With the pack manager, placing the Sizegrip at the bottom right can be achieved by setting side='right' and anchor='se'
For the grid system, you might reserve the bottom right cell for the Sizegrip by adjusting its row and column index appropriately, ensuring it's the last widget added to maintain its position.
When using place, precise positioning is possible by specifying the Sizegrip's relx and rely coordinates directly, usually based on the window's width and height to anchor it at the bottom right corner.
Event Binding for ttk Sizegrip Resizing window
We will print the size ( width and height ) of the window on resizing.
from tkinter import ttk
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("550x240") # width and height of window
my_w.title("www.plus2net.com") # title
my_w.rowconfigure(1,weight=1)
my_w.rowconfigure(2,weight=4)
my_w.columnconfigure(1,weight=1)
def my_resize(event):
lb1.config(text="Width : " + str(my_w.winfo_width())+ ", Height :" + str(my_w.winfo_height()))
s = ttk.Style()
s.configure('TSizegrip', background='red')
font1=['Times',16,'normal'] # font family , size and style
lb1=tk.Label(my_w,text='',height=3, bg='yellow',font=font1)
lb1.grid(row=1,column=1,padx=20,pady=20)
sizegrip = ttk.Sizegrip(my_w)
sizegrip.grid(row=2,column=1,sticky='se')
my_w.bind("<Configure>", my_resize)
my_w.mainloop() # Keep the window open