第一:
class UIDebugFrom(QWidget,debug_Widget): def __init__(self): super(UIDebugFrom,self).__init__() self.setupUi(self) # 创建窗口 Station1.stationname(self.tree_Widget) ''' def stationname(self): root = QTreeWidgetItem(self.tree_Widget) root.setText(0, 'root') self.tree_Widget.addTopLevelItem(root) self.tree_Widget.clicked.connect(self.onClicked1) def onClicked1(self): item = self.tree_Widget.currentItem() print(item.text(0)) ''' 当stationname和onClicked1这两个函数写在这个继承的类中时,不报错, 但是当单独提取这两个函数作为一个py文件,通过Station1.stationname(self.tree_Widget)导入到类中时, 就会进行