此代码有效:
import sys
from PyQt4 import QtCore, QtGui, QtWebKit
from forma import Ui_MainWindow
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton,QtCore.SIGNAL("clicked()"), self.strona)
def strona(self):
self.ui.webView.setUrl(QtCore.QUrl("http://plemiona.pl"))
但是这个
funkcje.py
from PyQt4 import QtCore, QtGui, QtWebKit
from forma import Ui_MainWindow
def strona():
self.ui.webView.setUrl(QtCore.QUrl("http://xxxx.pl"))
import sys, time, funkcje
from PyQt4 import QtCore, QtGui, QtWebKit
from forma import Ui_MainWindow
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton,QtCore.SIGNAL("clicked()"), funkcje.strona)
不工作...
Traceback (most recent call last):
File "C:\Python33\liczbapierwsza\TribalWarsBot\funkcje.py", line 5, in przejdz_na_strone_plemion
QtGui.QWidget.__init__(self, parent)
NameError: global name 'self' is not defined
如何从 funkcje.py 导入函数并在 ex run.py 中使用