我使用了TypeError:“place_configure()接受1到2个位置参数,但给出了3个”。我不明白为什么tkinter会对我给place方法提供的参数数量有问题。通常我会在硬编码风格中放置(x=45,y=240)并一直更改y值。现在我想让使用变量变得更容易,以防有人想要改变值一次。当我这样做时,错误出现了。谢谢你的帮助。
x = 45;
y = 240;
self.counter = 0
# Creation of checkbuttons
self.values_checkboxes_bitness={"32 and 64 Bit": 0, "32 Bit": 1, "64 Bit": 2}
self.values_checkboxes_debugRelease={"rebug and release": 0, "debug": 1, "release": 2}
for text in self.values_checkboxes_bitness:
self.counter+=1
bitnessCB = Checkbutton( text=text,variable=self.int_var_one, onvalue=self.values_checkboxes_bitness[text], offvalue=3,
command=partial(self.checkbox_clicked, self.int_var_one, self.int_var_one_comp,
self.int_var_one_no_checkout,
self.int_var_one_buildtype))
bitnessCB.pack()
bitnessCB.config(font=("Helvetica", 10))
for text in self.values_checkboxes_debugRelease:
self.counter+=1
relDebCB = Checkbutton(text=text,variable=self.int_var_one_comp, onvalue=self.values_checkboxes_debugRelease[text], offvalue=3,
command=partial(self.checkbox_clicked, self.int_var_one, self.int_var_one_comp,
self.int_var_one_no_checkout,
self.int_var_one_buildtype))
relDebCB.config(font=("Helvetica", 10))
if self.counter > 0:
y += 30
relDebCB.place(x,y)
else:
relDebCB.place(x,y)```
TypeError: place_configure() takes from 1 to 2 positional arguments but 3 were given
发布于 2020-07-22 12:25:32
当您使用调用relDebCB.place(x,y)
时,需要向.place()
方法传递三个参数。第一个参数是存储在relDebCB
中的对象。另外两个是位置参数。
因此,如果您的方法定义只有两个参数,那么您将多传递一个参数。
由于您没有提供代码,我猜函数定义如下所示:
def place(x,y):
pass ## Here goes your code
相反,它应该看起来像这样:
def place(self,x,y):
pass ## Here goes your code
类的任何方法中的第一个参数都应该是self
,因为传递给任何方法的第一个参数就是对象本身。
编辑:当然,除非你没有.place()
方法,但是想要使用tkinter的位置管理器,如Space所评论的。然后,您只需使用命名参数而不是位置参数来调用它:
relDebCB.place(x=x,y=y)
发布于 2020-07-22 12:56:51
必须以键-值对的形式指定x
和y
参数。
将relDebCB.place(x,y)
更改为relDebCB.place(x=x,y=y)
发布于 2020-07-22 13:49:15
关于place
方法的奇怪之处在于,第一个参数指定是否要将其移动到另一个主/根窗口,这并不常见。因此,您必须使用键-值对指定x位置和y位置,如下所示:
widget.place(x = x, y = y)
您还可以使用relx
和rely
,它们指定要将其移动到的页面的百分比。例如,将其移动到中心,并使其停留在那里,而不考虑屏幕大小,将需要以下代码:
widget = Frame(..., anchor = CENTER)
widget.place(relx = 0.5, rely = 0.5)
您必须将锚点指定为CENTER
,或者您可以使用"center"
,因为它们是相同的。
https://stackoverflow.com/questions/63033860
复制相似问题