wxpython无法导入同一目录中的文件

时间:2018-05-31 14:50:21

标签: python-3.x import wxpython

我想用wxpython制作一个简单的gui(在python 3.6.1中),因为我不想再使用该项目的命令行了。

我在另一个文件中有一个大文件,其他非wxpython文件也使用它。

但是当我尝试导入我的Logic类时,我收到此错误:

  

ImportError:无法导入名称'QuestionAsk'

我使用此行导入Logic类:

from Get import QuestionAsk

文件“Get.py”与gui文件位于同一目录中。 Here

但它不起作用的原因以及如何导入此文件?

顺便说一句,我从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

修正了它(yay):

我从Get.py文件中删除了graphical_start函数并将其粘贴到gui.py文件中。我现在直接从Asker.py文件导入Gui.py文件。

0 个答案:

没有答案
相关问题