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.
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.
-> To make window non-resizable user can pass 0 or False.
The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With