为什么Tkinter画布要求4个额外的像素作为宽度和高度?

2024-09-27 22:35:56 发布

您现在位置:Python中文网/ 问答频道 /正文

>>> import Tkinter
>>> c = Tkinter.Canvas(width=100, height=100)
>>> c.winfo_reqwidth()
104
>>> c.winfo_reqheight()
104

如果将borderwidth设置为零,结果是相同的。我找不到解释或控制这4个额外像素的设置或属性。在


Tags: import属性tkinter像素widthcanvasheightwinfo
2条回答

因为winfo_reqwith()winfo_reqheight()方法不返回小部件的实际宽度和高度。文件上是这样写的:

winfo_reqheight(), winfo_reqwidth().

Return the "natural" height (width) for self. The natural size is the minimal size needed to display the widget's contents, including padding, borders, etc. This size is calculated by the widget itself, based on the given options. The actual widget size is then determined by the widget's geometry manager, based on this value, the size of the widget's master, and the options given to the geometry manager.

明白了!在

c = Tkinter.Canvas(width=100, height=100, highlightthickness=0)
>>> c.winfo_reqwidth()
100

我调试问题的方式可能对其他需要帮助的人也有用:

^{pr2}$

所以在看了这一整套配置后,我猜它要么是highlight参数,要么是closeough参数。在

相关问题 更多 >

    热门问题