调整窗口大小时如何使 Tkinter 消息展开? [英] How to make Tkinter message expand when I resize the window?

查看:30
本文介绍了调整窗口大小时如何使 Tkinter 消息展开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个 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.

推荐答案

调整窗口大小时需要设置 Message 文本的宽度.据我所知,没有办法告诉 Message 小部件自动执行此操作,因此您只能使用回调:

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()

这篇关于调整窗口大小时如何使 Tkinter 消息展开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆