Tkinter Inner Padding 不能只在一侧 [英] Tkinter Inner Padding can't be on only one side

查看:34
本文介绍了Tkinter Inner Padding 不能只在一侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能会令人困惑,但出于某些奇怪的原因,在 .pack() 中使用 ipadxipady(1,0) 或者像这样:Label(root, text='Hello World').pack(ipadx=(1,0)) 总是会出现这个错误:TclError: badipady 值1 0":必须为正屏幕距离.尝试其他类似的东西: Label(root, text='Hello World').pack(ipadx=1) 工作得很好.但是这个说:

This might be confusing but for some odd reason using ipadx or ipady in .pack() with (1,0) or like this: Label(root, text='Hello World').pack(ipadx=(1,0)) will always make this error: TclError: bad ipady value "1 0": must be positive screen distance. Trying other things like: Label(root, text='Hello World').pack(ipadx=1) work just fine. But This Said:

填充选项(padx、ipadx、pady 和 ipady)可以采用 2 元组来表示左/右和上/下填充.

The padding options (padx, ipadx, pady and ipady) can take a 2-tuple that represent the left/right and top/bottom padding.

那么,发生了什么......

So, what is happening...

这里有一些完整的代码也有错误:

And here's some complete Code that has the error too:

from Tkinter import *

root = Tk()

Label(root, text='Hello World').pack(ipadx=(1, 0))

root.mainloop()

更新:我发现你不能在 Tkinter,甚至 Tcl/Tk 中做到这一点......

Update: I found that you can't do that in Tkinter, or even Tcl/Tk...

推荐答案

您链接的答案有误,我会更新.ipadxipady 不支持元组作为参数.来自 官方 tcl/tk 文档:

The answer you linked to is wrong, and I'll update it. ipadx and ipady do not support a tuple as an argument. From the official tcl/tk docs:

-ipadx 数量

Amount 指定要在从属设备的每一侧保留多少水平内部填充.Amount 必须是有效的屏幕距离,例如 2 或 .5c.默认为 0.

Amount specifies how much horizontal internal padding to leave on each side of the slave(s). Amount must be a valid screen distance, such as 2 or .5c. It defaults to 0.

-ipady 金额

Amount 指定在从属设备的每一侧留下多少垂直内部填充.金额默认为 0.

Amount specifies how much vertical internal padding to leave on each side of the slave(s). Amount defaults to 0.

-padx 数量

Amount 指定在从属设备的每一侧留下多少水平的外部填充.Amount 可能是一个包含两个值的列表分别为左右指定填充.金额默认为 0.

Amount specifies how much horizontal external padding to leave on each side of the slave(s). Amount may be a list of two values to specify padding for left and right separately. Amount defaults to 0.

-pady 金额

Amount 指定要在从属设备的每一侧留下多少垂直外部填充.Amount 可以是两个要指定的值的列表分别为顶部和底部填充.金额默认为 0.

Amount specifies how much vertical external padding to leave on each side of the slave(s). Amount may be a list of two values to specify padding for top and bottom separately. Amount defaults to 0.

这篇关于Tkinter Inner Padding 不能只在一侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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