How to stop Tkinter Message widget from resizing?


Tkinter Message widget is generally used to display text messages in a tkinter window. The Tkinter Message widget can also be configured by adding different properties to it, for example, font-properties, background and foreground color properties, and padding to widen the corners of the box, etc.

Let us assume that we want to stop the Message widget from resizing, then we can use the fill=BOTH property in pack geometry manager while packing the Message widget. Let's take an example to demonstrate how it works.

Example

# Import the required library
from tkinter import *

# Create an instance of tkinter frame or widget
win = Tk()

# Size of the window
win.geometry("700x350")

# Create a Non-resizable messagebox
msg=Message(win, text="Hi, how are you doing?")
msg.config(bg='yellow', font=('Calibri', 16), borderwidth=2)
msg.pack(fill=BOTH)

# Run the mainloop
win.mainloop()

Output

It will produce the following output −

Here, if you stretch the window, the Messagebox will resize automatically.

Without the fill=BOTH parameter, the same code will produce the following output −

In this case, the width of the Messagebox will remain fixed irrespective of the size of the window.

Updated on: 22-Dec-2021

372 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements