Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Tkinter message expand when I resize the window?

Tags:

python

tkinter

I'm trying to get a tkinter message widget to make the words move when I resize the window. Right now, the window is a small block, and the line of text is an ugly block. How can I make it expand. This is the code I have.

root = Tk()
Message(text="This is a Tkinter message widget. Pretty exiting, huh? I enjoy Tkinter. It is very simple.").pack()
root.mainloop()

I hope you understand my question. Thanks.

like image 772
uncleshelby Avatar asked Dec 02 '11 22:12

uncleshelby


People also ask

How to create a resizable window in tkinter?

The geometry(width, height)method takes width and height as instances and resizes the window accordingly. We can also define the position of the tkinter window by adding geometry(width x height, X, Y) where x and y are horizontal and vertical positions of the window.

What statement you will write to prevent the user from resizing the window at runtime in Python?

-> To make window non-resizable user can pass 0 or False.

How do I lock the size of a tkinter window?

The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .


1 Answers

You need to set the width of the Message text when you resize the window. As far as I know, there is no way to tell the Message widget do that automatically, so you're stuck with using a callback:

from tkinter import Tk, Message

root = Tk()
m = Message(text="This is a Tkinter message widget. Pretty exiting, huh? I enjoy Tkinter. It is very simple.")
m.pack(expand=True, fill='x')
m.bind("<Configure>", lambda e: m.configure(width=e.width-10))
root.mainloop()
like image 98
Dave Avatar answered Oct 11 '22 18:10

Dave