在其他功能中使用本地按钮

2024-04-18 16:05:17 发布

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

我有下面的代码,问题是我不能在Marca3中使用一个按钮是在Marca2中创建的,所以我不能删除它。我想那是因为不是在同一个函数中创建的。 Supose对象C1已经创建

代码:

#The error says 'AttributeError: 'NoneType' object has no attribute 'destroy''

import Tkinter
den = tkinter.Tk()

def Marca2(b):
    if b == 1:
        C1.destroy()
        J1 = Button(MenuP, text = "J1",command = lambda: Definir(1,0)).place(x = 100,y = 100) #Here is created the button

def Marca3(b):
    if b == 1:
        J1.destroy() #Here is where i use that button
        C1 = Button(MenuP, text = "1",command = lambda: Definir(1,0)).place(x = 100,y = 100)

Marca2(1)
Marca3(1)


den.mainloop()

Tags: lambda代码textifdefbuttoncommandc1