出走的蚂蚁
2022-06-12 17:48
采纳率: 60%
浏览 17

用PyCharm进行QT编程出现路径错误

用PyCharm进行QT编程出现路径错误
主函数如下:

mport sys
from PyQt5.QtWidgets import QApplication,QMainWindow
import test

class MyMainWindow(QApplication,test1.Ui_MainWindow):
def init(self,parent=None):
super(MyMainWindow,self).init(parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.turn_on_off)
self.turn_off = QPixmap('E:\桌面文件\Python\Qt_study\img\off.jpg')
self.turn_on = QPixmap('E:\桌面文件\Python\Qt_study\img\on.jpg')
self.label.setPixmap(self.turn_on)
self.click_time = 0

def turn_on_off(self):
self.click_time += 1
if self.click_time % 2 == 0:
self.label.setPixmap(self.turn_off)
self.pushButton.setText("开")
else:
self.label.setPixmap(self.turn_on)
self.pushButton.setText("关")

if name == 'main':
app = QApplication(sys.argv)
myMainWindow = MyMainWindow()
myMainWindow.show()
sys.exit(app.exec())

test1.py
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1160, 824)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.toolButton = QtWidgets.QToolButton(self.centralwidget)
self.toolButton.setGeometry(QtCore.QRect(390, 420, 391, 101))
self.toolButton.setObjectName("toolButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(400, 150, 371, 241))
self.label.setStyleSheet("")
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1160, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.toolButton.setText(_translate("MainWindow", "开"))
self.label.setText(_translate("MainWindow", "TextLabel"))

运行结果及报错内容

D:\python3.8\python.exe: can't open file 'E:/桌面文件/main.py': [Errno 2] No such file or directory

我的解答思路和尝试过的方法

想要更改 python dir 但是没找到

我想要达到的结果

1条回答 默认 最新

相关推荐 更多相似问题