在组成上,内容可以使用容器的对象而不是“自身”吗?

时间:2019-02-08 10:38:17

标签: python pyqt4

我正在使用qt designer和python制作Gui。我在demo.py和demo2.py上有两个类,它们位于同一目录/文件夹中。当单击demo时,我可以显示demo2并使用OOP组合隐藏演示像下面一样 但是后来我很困惑,为什么我不能隐藏demo2(像下面这样)。 这是demo.py

From demo2 import Ui_Form
Class Ui_For(object):
    def log(s):
        s.U=QtGui.QWidget()
        s.x=Ui_Form()
        s.x.setupUi(s.U)
        s.U.show()
        Form.hide()
    def setupUi(self,Form):
        '''the things that are going to be stated here are the Qlabels(QtGui.Qlabel),Qline edit,the button that connects to method log also,which is working good and other things of this window just like the qt designer write it'''
If __name__=='__main__':
    import sys
    app=QtGui.QApplication(sys.argv)
    Form=QtGui.QWidget()
    ui=Ui_For()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

这是demo2

Class Ui_Form(object):
      def oy(o):
          ui.U.hide()#this the the one bringing error
      def setupUi(self,Form):
          '''And the rest of the code(there is push button here that connects to method oy,and it works good'''

当我进入demo2小部件时,当我按下按钮并连接到方法oy时,出现“未定义名称'ui'”的错误。但是为什么?

我尝试过的事情:

1。def oy(o): o.x=3 print(getattr(o,'x'))#works great and gives me 3 as expected

但是如果我改为这样做,`

print(getattr(ui.x,'x'))#i get "name 'ui' is not defined" error

这是为什么?在这种情况下,“ o”与“ ui.x”不同吗?

0 个答案:

没有答案