pyqt4 - python,pyqt,一个文件用另一个文件的全局变量,居然报'module' object has no attribute
高洛峰
高洛峰 2017-04-18 10:10:08
0
2
834
这个是uitest.py文件的

if __name__ == "__main__":
    global ui
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())
    
这个是另一个py文件,我想调用上面那个py文件的ui变量,然后报错'module' object has no attribute ‘ui'

uitest.ui.tableWidget.setColumnCount(9)
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
巴扎黑

I don’t quite understand why the questioner did this, but if you want to get the variables of another file, I suggest you write a function, which is better.

For example, if the variable ui you want to call is in the test1.py file, then you can write such a function in test1.py

class Test():
    def __init__():
        ...
        
    def getUi():
        return ui

Then in test2.py code example:

test = Test()
ui = test.getUi()

That’s it

阿神

How did you import uitest?


Change it to this~

global ui
if __name__ == "__main__":
    #…………
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!