PyQT无法从单独的类访问GUI信息?

时间:2019-01-11 15:06:07

标签: python python-3.x pyqt qt5 pyqt5

我遇到了无法从单独的类方法访问PyQT QTextEdits和QLineEdits的问题。我得到了该错误的不同变体:

  

AttributeError:类型对象'MyApp'没有属性'Ui_MainWindow'

我已经尝试了所有我能想到的,包括:

  • 使用儿童班
  • 在非子类中明确添加GUI类作为参数
  • 使用“ self..text()”调用项目
  • 使用“ MyApp..text()”(GUI附带的类名称)调用项目
  • 使用“ MyApp.Ui_MainWindow..text()”(GUI附带的类名称)调用项目
  • 使用“ MyApp.Ui_MainWindow.setupUi..text()”(GUI附带的类名称)调用项目
  • 使用“ UiMainWindow..text()”(导入的GUI .py文件类)调用项目
  • 使用“ UiMainWindow.setupUi..text()”(导入的GUI .py文件类+方法)调用项目
  • 使用“ UiMainWindow.setupUi..text()”(导入的GUI .py文件类+方法)调用项目

请在下面查看我的代码:

from app import Ui_MainWindow #import UI


class MyApp(QtWidgets.QMainWindow, Ui_MainWindow): #GUI class
  def __init__(self):
    QtWidgets.QMainWindow.__init__(self)
    Ui_MainWindow.__init__(self)

    self.button_search_item.clicked.connect(new_class.get_information)

class new_class(MyApp): #new class that i want to call on qtext and qline edits.
def get_information(self):
    print(str(MyApp.Ui_MainWindow.setupUi.qlineedit_item.text()))


#OUTPUT: 
#AttributeError: type object 'MyApp' has no attribute 'Ui_MainWindow'

0 个答案:

没有答案
相关问题