如何从python / gtk中的类传递变量?

时间:2012-09-26 03:39:56

标签: python gtk

我正在使用gtk在python中开发一个程序来为程序创建GUI,这个程序我试图将我在类A中创建的变量传递给B类,但是我无法做到,我正在尝试做这样的事情:

class ClassA(gtk.Window):
    def __init__(self):
        super(ClassA, self).__init__()
        self.set_position(gtk.WIN_POS_CENTER)
        self.button = gtk.Button("Button")
        self.button.connect("clicked", self.on_clicked)

    def on_clicked(self, *args):
        variable = "value"
        ClassB(variable)

class ClassB(variable, gtk.Window):
    def __init__(self):
        super(ClassB, self, variable).__init__()
        self.set_position(gtk.WIN_POS_CENTER)
        self.button = gtk.Button("Button")
        self.button.connect("clicked", self.on_clicked)
    def on_clicked(variable, *args):
        print variable

if __name__ == '__main__':
    app = ClasseA()
    gtk.main()

谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

class ClassB(gtk.Window):
    def __init__(self, variable):
        #Your code
        self.variable = variable