【发布时间】:2021-06-19 00:51:02
【问题描述】:
我正在尝试在我的应用程序末尾创建一个帮助菜单。我也使用了Message 小部件。我的窗口基本上是一个有 2 列的网格。我已将消息小部件放在最后,并将其跨越两列,但是由于某种原因,小部件并未占用整个水平空间。有什么方法可以强制它占据所有水平空间(同时确保文本换行如下所示)?
程序代码:
self.helpDesc = """Help:
1. The URL textbox specified the URL to be watched. In order to verify whether the given URL is valid according to the program one could wait for the status code of the URL to appear in the next line.
2. Testing Again
"""
self.helpBox = Message(self, text=self.helpDesc, anchor='w')
self.helpBox.grid(row=10, column=0, columnspan=2, sticky=N+S+W+E, padx=8, pady=8)
输出:
【问题讨论】:
-
尝试将
padx和pady设置为零。它们是添加到小部件外部的外部填充。 -
不,没有什么大的区别(只是左边的填充消失了)
-
anchor='c'? -
尝试改用
Label或Text小部件。您必须自己用前者包装文本(但使用textwrap模块很容易)。