Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python子类触发父类_Python_Python 2.7 - Fatal编程技术网

Python子类触发父类

Python子类触发父类,python,python-2.7,Python,Python 2.7,我需要在python中从子对象修改父对象上声明的对象。我知道在java中,通过在初始化子对象时将父对象作为参数传递,可以从子对象修改父对象。我不需要从父级继承到子级,我只需要子级显示和隐藏在父级上声明的帧。例如在Java中 public class Parent(){ public Child1 objtchild1; public Parent(){ ] Child2 panel = new Child2(this); Child1 objtch

我需要在python中从子对象修改父对象上声明的对象。我知道在java中,通过在初始化子对象时将父对象作为参数传递,可以从子对象修改父对象。我不需要从父级继承到子级,我只需要子级显示和隐藏在父级上声明的帧。例如在Java中

public class Parent(){
    public Child1 objtchild1;
    public Parent(){ ]
        Child2 panel = new Child2(this);
        Child1 objtchild1 = new Child1();
}
public class Child1 (){
     public int var = 1;

}
public class Child2 () {
    private Parent parent;
    public Child(Parent parent)  {
        this.parent = parent;
        parent.objtchild1.var=2;//Modify parent child object

}
我想在视图与控制器交互的地方应用模型视图控制器。就像下面的url一样,但是在python中。

上面关于Java的示例是否可以在python中使用?

与python中的Java代码等效的是:

class Parent(object):
    def __init__(self):
        # make sure to make objtchild1 first, as panel will try and alter it
        self.objtchild1 = Child1()
        self.panel = Child2(self)

class Child1(object):
    def __init__(self):
        self.var = 1

class Child2(object):
    def __init__(self, parent):
        self.parent = parent

        # modify parent child object
        self.parent.objtchild1.var = 2

请提供一份报告。现在,解决方案必须基于我们对您的假设的解释,而不是代码的实际内容。代码可能不一定符合你的假设。我的解释是,你在以复杂的方式问一个简单的问题。在你提供之前无法确定。对此很抱歉。我只是最小化了我的问题,我需要在我的python项目中应用什么。这与tkinter有什么关系?我不知道你是什么意思,这与tkinter有什么关系?我想在python中应用模型-视图-控制器,以便视图与控制器交互以传递单击事件。这在python中可能吗?谢谢你为我节省了数小时的研究时间。我正在使用pycharm,当我键入self.parent时。它没有给我任何暗示。很好用,谢谢。