How to Use the Tkinter Sizegrip Widget (original) (raw)

Summary: in this tutorial, you’ll learn how to use the Tkinter Sizegrip widget that allows you to resize the entire application window.

The Sizegrip widget is typically located in the bottom-right corner of the window. It allows you to resize the entire application window:

To create a Sizegrip widget, you use the following syntax:

ttk.Sizegrip(master, **kw)Code language: Python (python)

In this syntax:

To make sure the Sizegrip widget works properly, you need to make the parent widget resizable.

If you use the main window e.g., root, you need to call the resizable() method with True values:

root.resizable(True, True)Code language: PHP (php)

Let’s take some examples of using the Sizegrip widget.

1) Using the Sizegrip widget with a grid layout #

The following program creates and shows Sizegrip at the bottom-right corner of the main window using the grid layout:

`import tkinter as tk from tkinter import ttk

root = tk.Tk() root.title('Sizegrip Demo') root.geometry('300x200') root.resizable(True, True)

grid layout

root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1)

create the sizegrip

sizegrip = ttk.Sizegrip(root) sizegrip.grid(row=1, sticky=tk.SE)

root.mainloop()`Code language: Python (python)

Output:

Tkinter Sizegrip Widget Demo

How it works.

First, make sure the root window is resizable:

root.resizable(True, True)Code language: Python (python)

Second, configure the grid layout:

root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1)Code language: Python (python)

Third, create a Sizegrip widget and place at the bottom-right corner of the window:

sg = ttk.Sizegrip(root) sg.grid(row=1, sticky=tk.SE)Code language: Python (python)

2) Using the Sizegrip widget with the place layout #

The following program demonstrates how to create a Sizegrip widget and place it at the bottom-right corner of the window using the place() method:

`import tkinter as tk from tkinter import ttk

root = tk.Tk() root.resizable(True, True)

create a sizegrip and place it at

the bottom-right corner of the window

sizegrip = ttk.Sizegrip(root) sizegrip.place(relx=1, rely=1, anchor=tk.SE)

root.mainloop()`Code language: Python (python)

In this example, we set the relx and rely parameters of the place() method to 1.0 to place the Sizegrip widget at the bottom-right corner of the main window. We also set the anchor parameter to tk.SE to place the south-east point of the Sizegrip to the specified coordinates.

3) Using the Sizegrip widget with the pack layout #

The following program creates a Sizegrip widget and places it at the bottom-right corner using the pack() method:

`import tkinter as tk from tkinter import ttk

root = tk.Tk() root.geometry('300x200') root.resizable(True, True)

Pack the Sizegrip at the

bottom-right corner of the window

sizegrip = ttk.Sizegrip(root) sizegrip.pack(side="bottom", anchor=tk.SE)

root.mainloop() `Code language: Python (python)

In this example, we set the side parameter to “bottom,” and the anchor parameter to “se” to position the Sizegrip at the bottom-right corner of the window.

Summary #

Was this tutorial helpful ?