Learn how to enable or disable the maximize button in a Tkinter or ttkbootstrap window using Python 3

RSDevX
3 min readApr 9, 2024

--

In this medium post, you will learn how to enable or disable the Maximize Button in a Tkinter or ttkbootstrap Window using Python.

Whether you’re crafting GUI applications or utilizing tkinter/ttkbootstrap, understanding the maximize button’s behavior is crucial for enhancing user experience.

Follow my straightforward guide to effortlessly control the maximize button and learn to restrict window resizing along specific axes, enhancing your application’s usability and aesthetics.

Full Tutorial on

You will need to have a Python interpreter with tkinter/ttkbootstrap installed. You can check the below tutorial on how to install ttkbootstrap on Windows 10/11.

There are cases where we prefer to restrict the user from maximizing or minimizing the Tkinter application window.

Resizable windows may result in inconsistent user experiences, particularly if the layout isn’t tailored to various sizes. Elements might misalign or overlap, diminishing the application’s intuitiveness and usability.

By employing fixed-size windows, developers gain greater control over the application’s design and layout. This ensures that UI elements are positioned and sized appropriately, enhancing both usability and aesthetics.

Here, we’ll delve into managing the resize property of the tkinter/ttkbootstrap window to prevent alterations to its shape or size

We can disable the maximize button on the window by calling the .resizable(x_axis,y_axis) method. It takes two arguments to disable or enable resize function in x or y axis.

root.resizable(0,0) #Disable resizing in all directions,Maximize button disabled
#root.resizable(x,y)

The code root.resizable(0, 0) is a configuration setting for a Tkinter window . This line of code controls whether the user can resize the window and in which directions.

Here’s what the parameters 0 and 0 mean in root.resizable(0, 0):

The first parameter (0) controls the window’s resizable behavior in the x-direction (horizontal).

  1. If set to 1, it allows resizing in the x-direction.
  2. If set to 0, it prevents resizing in the x-direction.

The second parameter (0) controls the window’s resizable behavior in the y-direction (vertical).

  1. If set to 1, it allows resizing in the y-direction.
  2. If set to 0, it prevents resizing in the y-direction.

So, root.resizable(0, 0) disables resizing in both the x-direction and y-direction, effectively preventing the user from resizing the window in any direction.

Additionally, by setting both parameters to 0, the maximize button of the window is also disabled, meaning the window cannot be maximized by the user.

root.resizable(1,0) #Enable Resize in X direction only 
#Disable resizing y direction only

Here's what the parameters 1 and 0 mean in root.resizable(1, 0) in the above code

The first parameter (1) controls the tkinter window's resizable behavior in the x-direction (horizontal):

  1. If set to 1, it allows resizing in the x-direction.
  2. If set to 0, it prevents resizing in the x-direction.

The second parameter (0) controls the window's resizable behavior in the y-direction (vertical):

  1. If set to 1, it allows resizing in the y-direction.
  2. If set to 0, it prevents resizing in the y-direction.

So, root.resizable(1, 0) enables resizing in the x-direction only, allowing the user to resize the window horizontally but not vertically. This means that the user can adjust the width of the tkinter window, but its height remains fixed.

root.resizable(0,1) #Disable Resize in X direction only 
#Enable resizing y direction only

Here's what the parameters 0 and 1 mean in root.resizable(0, 1):

The first parameter (0) controls the window's resizable behavior in the x-direction (horizontal):

  1. If set to 1, it allows resizing in the x-direction.
  2. If set to 0, it prevents resizing in the x-direction.

The second parameter (1) controls the window's resizable behavior in the y-direction (vertical):

  1. If set to 1, it allows resizing in the y-direction.
  2. If set to 0, it prevents resizing in the y-direction.

So, root.resizable(0, 1) disables resizing in the x-direction only, meaning that the user cannot adjust the width of the window horizontally. However, it enables resizing in the y-direction, allowing the user to adjust the height of the window vertically.

While there are valid reasons for not allowing window resizing in Tkinter applications, it ultimately depends on the specific requirements and design considerations of the application

--

--