我怎样才能把一个方法变成一个整数呢

2024-04-20 16:26:50 发布

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

我试着与tkinter按钮,试图使它这样当你关闭一个按钮,它会创建另一个按钮。但我想试着让它,无论你关闭多少次第一个按钮,它不会创造更多的。你知道吗

我试过用比较法,但它说

TypeError: '<' not supported between instances of 'method' and 'int' 

我想知道如何将一个方法转换成一个整数,或者只是一个更好的想法

if self.printbutton < 1:
            self.printbutton()

我希望它只创建一个按钮。除非没有打印按钮。你知道吗


Tags: andofinstances方法selftkinternotbetween
1条回答
网友
1楼 · 发布于 2024-04-20 16:26:50

天哪! 在tkinter中,按钮操作在config中

command =<method> 

让我们只流行一次(…), 如果它像

button.config( command = partial(pop_only_once,...,button))

因此,要使其成为唯一的方法,请在方法内部编写:

def pop_only_once(..., button)

...

button.config( command =None)

相关问题 更多 >