TKinter:在Python类中获取变量并将其发送给另一个

2024-06-25 23:11:30 发布

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

我需要将一个变量从一个类发送到另一个类

我的代码:

我得到的类是可变的

class Application(tk.Tk):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        #TOOLBAR MENU
        toolbar = tk.Frame(self, bd = 1, relief = tk.RAISED)

        self.choicebutton = tk.Button(toolbar, command=self.choice)

        #TOOLBAR MENU
        toolbar = tk.Frame(self, bd = 1, relief = tk.RAISED)

I类导入变量:

class Frame1(tk.Frame):

    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        

        a.Application.choicebutton.config(state="disabled")

我得到一个错误:

AttributeError: type object 'Application' has no attribute 'choicebutton'

Tags: selfapplicationinitdefargsframebdkwargs
2条回答

假设parentApplication对象:

class Frame1(tk.Frame):

    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        parent.choicebutton.config(state="disabled")

将最后一行更改为

a.Application().choicebutton.config(state="disabled")

相关问题 更多 >