Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter如何安装非对称按钮_Python_Tkinter_Tkinter Button - Fatal编程技术网

Python Tkinter如何安装非对称按钮

Python Tkinter如何安装非对称按钮,python,tkinter,tkinter-button,Python,Tkinter,Tkinter Button,正如您在图片中所看到的,所有内容都正确对齐,但“等式”按钮在两侧的大小并不对称。例如,如果我将等式字符更改为一个数字,那么一切都是完美的。我试图搜索是否可以只在按钮的一侧(而不是网格)添加填充,但找不到解决方案。有没有办法解决这个问题 以下是按钮的当前代码: button_equation = Button(window, text="=", bg=button_bg, fg=button_fg, activeforeground=button_afg,

正如您在图片中所看到的,所有内容都正确对齐,但“等式”按钮在两侧的大小并不对称。例如,如果我将等式字符更改为一个数字,那么一切都是完美的。我试图搜索是否可以只在按钮的一侧(而不是网格)添加填充,但找不到解决方案。有没有办法解决这个问题

以下是按钮的当前代码:

button_equation = Button(window, text="=", bg=button_bg, fg=button_fg, activeforeground=button_afg,
                     activebackground=button_abg, highlightbackground=button_afg, borderwidth=button_border,
                     padx=26, pady=0, font=(font, 16))

您可以通过将小部件放在元组中向其一侧添加填充:
padx=(左、右)
pady=(上、下)
。另外,向我们展示用于该按钮的代码。这会在小部件中导致错误,例如,如果我写入padx=(1,1),错误是“_tkinter.TclError:bad screen distance“1 1”。Tuple在网格配置中工作,但我无法使其在小部件配置中工作。您应该将其与网格一起使用,而不是作为小部件选项使用。
button\u equation.grid(…,padx=(…))
/如果在这些按钮上使用了
grid()
,请添加
sticky=“ew”