【问题标题】:how can i import other module class in visual studio code如何在 Visual Studio 代码中导入其他模块类
【发布时间】:2021-06-09 22:12:39
【问题描述】:

我的问题是我使用 Visual Studio 代码编写 python 程序, 但我无法将其他模块类(Ui_Form)导入当前模块

这是我当前的模块:

from PyQt5.QtWidgets import *
from HR_System.view.main_window import Ui_Form

    class MainWindow(QWidget,Ui_Form):
        def __init__(self):
            QWidget.__init__(self)
            self.setupUi(self)
    
    app = QApplication([])
    window=QWidget()
    window.show()
    app.exec()

原模块(路径:HR_System.view.main_window):

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1024, 700)
        font = QtGui.QFont()
        font.setFamily("Terminal")

enter image description here

enter image description here

json 启动:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-msedge",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

为什么没有模块??我使用 python 3.8.6

【问题讨论】:

  • 你能发布关于你项目的文件夹结构和错误的截图吗?
  • 我添加了 2 张截图,你可以检查一下吗

标签: python class visual-studio-code import


【解决方案1】:

launch.json中,添加

    "env": {
        "PYTHONPATH":"${workspaceFolder}"
    },

然后Run without Debugging,可以看到winform显示出来了:

【讨论】:

  • 谢谢,但我希望窗口在 Ui_Form 类表单 main_window 模块中具有相同的设计和功能:(
  • 你可以打开另一个关于python开发的问题。如果我的回答有助于解决您最初关于导入模块的问题,请mark 让更多有类似问题的人联系到它。
猜你喜欢
  • 1970-01-01
  • 2019-06-19
  • 2017-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-02
相关资源
最近更新 更多