请问为什么调用不了另一个py文件的函数呢 也用了from import了
这样字按钮点开后就会崩溃 函数不能导入y1.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QWidget,QApplication,QTextEdit,QVBoxLayout,QLabel
from PyQt5.QtGui import QDragEnterEvent,QPixmap
import os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from y2 import *
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.resize(640, 320)
self.bt = QPushButton('按钮',self)
self.bt.setGeometry(200, 150, 200, 121)
self.bt.clicked.connect(self.zyq)
def zyq(self):
y2.syq()
if __name__ == "__main__":
app = QApplication(sys.argv)
d = Example()
d.show()
sys.exit(app.exec_())
y2.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QWidget,QApplication,QTextEdit,QVBoxLayout,QLabel
from PyQt5.QtGui import QDragEnterEvent,QPixmap
import os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class Example2(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.resize(640, 320)
def xyq(self):
print('python')
if __name__ == "__main__":
app = QApplication(sys.argv)
q = Example2()
q.show()
sys.exit(app.exec_()) 你使用了from y2 import * 之后def zyq(self):
y2.syq()这个方法就不对,直接使用xyq() def zyq(self):
y2.syq()
这一段改成这样试试:
def zyq(self):
syq() class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.resize(640, 320)
self.bt = QPushButton('按钮',self)
self.bt.setGeometry(200, 150, 200, 121)
self.bt.clicked.connect(self.zyq)
def zyq(self):
return Example2.xyq(self)
页:
[1]