python-3.x - wxpython无法导入同一目录中的文件
问题描述
我想用 wxpython(在 python 3.6.1 中)制作一个简单的 gui,因为我不想再为这个项目使用命令行了。
我在另一个文件中有一个用于逻辑的大文件,其他非 wxpython 文件也使用该文件。
但是当我尝试导入我的逻辑类时,我得到了这个错误:
ImportError:无法导入名称“QuestionAsk”
我使用这条线来导入逻辑类:
from Get import QuestionAsk
文件“Get.py”与 gui 文件位于同一目录中。 这里
但它不起作用为什么以及如何导入这个文件?
顺便说一下,我从 get.py 文件中调用 gui.py 文件并从 Asker.py 文件中导入 get.py 文件。
ps:请尽量不要回答:“只需将该类的内容复制到您的gui文件中”,因为如果没有其他解决方案,我会在其他地方使用这个类,那没关系,但这只是丑陋和低效。
编辑这里是启动 Gui 的 Get 文件中的代码:
def graphical_start():
app = wx.App(False) # int app
frame = GuiVocCard() # set frame (GuiVocCard is in the main Gui File)
frame.Show() # show frame
app.MainLoop() # execute loop
这是 Gui 主类“GuiVocCard”的开始:
class GuiVocCard(wx.Frame):
def __init__(self):
self.language = "es"
self.transList = "C:\\Users\\Justus\\Desktop\\Schule\\spa\VocabGeter\\translations\\big_translation.json"
self.verb_forms = [0,2]
self.High_Score = 0
self.s_file = "scores.json"
self.S_chunk = 40
self.chunk_file = "chunks.json"
self.load_config()
self.q_ask = QuestionAsk(lan=self.language, trans=self.transList, verb_forms=self.verb_forms,
scores_file=self.s_file, chunks_file=self.chunk_file, chunk_size=self.S_chunk)
...
编辑 2:
QuestionAsk 在 Get.py 文件中定义:
class QuestionAsk:
def __init__(self,lan="es",trans="C:\\Users\\Justus\\Desktop\\Schule\\spa\VocabGeter\\translations\\translation.json"
,verb_forms=[0,2],scores_file="scores.json",chunks_file="chunks.json",chunk_size=40):
self.language = lan
self.transList = trans
self.verb_forms = verb_forms
self.High_Score = 0
self.s_file = scores_file
self.S_chunk = chunk_size
self.chunk_file = chunks_file
修复它(耶):
我从 Get.py 文件中删除了 graphics_start 函数并将其粘贴到 gui.py 文件中。我现在直接从 Asker.py 文件中导入 Gui.py 文件。
解决方案
推荐阅读
- java - RxJava Single.just() vs Single.fromCallable()?
- psych - PsychToolBox:将输入从 GUI 传递到简单的巴甫洛夫脚本时出错
- python - 如何列出 S3 存储桶分隔符路径
- ios - Mapbox iOS SDK 动态样式坐标边界崩溃
- swift - 在初始化期间使用覆盖的静态属性
- java - 带有 Jersey 和 Micrometer 的 Prometheus 端点中的模板化 URL
- ios - Nativescript:当应用程序进入后台时继续执行代码
- processing - 我需要同时将两个椭圆从 X_start 移动到 X_END 并返回到 X_START
- php - 如果我使用 PHP 或 AJX 从我的数据库返回包含数据的格式化 html,这有关系吗?
- ios - 当已知数据和编码有效时,还有什么其他原因可能导致 NSString initWithData 返回 nil?