[英]PyQt5 method not connected to button
This is my code for running PyQt, however the selectFile method is not called by the button. 这是我运行PyQt的代码,但是按钮未调用selectFile方法。 The UI code is converted from QtCreator.
UI代码是从QtCreator转换而来的。 I've checked my objectName for the button is browseCSV
我已经检查了我的按钮的objectName是browserCSV
import sys
from readCSV import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
import form
from function2 import *
from function4 import *
from Function6 import *
class App(QtWidgets.QMainWindow, form.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self) # This is defined in design.py file automatically
self.browseCSV.clicked.connect(self.selectFile)
def selectFile(self):
print ("Hello")
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = form.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
You're not actually using your App
class. 您实际上并没有使用
App
类。 So you need to do this: 因此,您需要这样做:
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = App()
window.show()
sys.exit(app.exec_()
PS: don't ever use self.__class__
in a super
call. PS:永远不要在
super
调用中使用self.__class__
。 In some scenarios, it can cause an infinite regress. 在某些情况下,它可能导致无限回归。 If you're using Python 3, you can just use
super().__init__()
to avoid repeating the class name. 如果您使用的是Python 3,则可以只使用
super().__init__()
以避免重复类名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.