没有名为'x'的模块; “X”是不是一个包
问题描述:
这是当我尝试导入与使用按钮的其他tkinter文件时出现的错误:没有名为'x'的模块; “X”是不是一个包
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Feargus\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Feargus\Documents\COMPUTING\games\BIG_MAIN_MENU.py", line 13, in settingsButton
import SETTINGS.py
ModuleNotFoundError: No module named 'SETTINGS.py'; 'SETTINGS' is not a package
这里是一个导入文件的代码:
def startGame():
import GAME.py
def settingsButton():
import SETTINGS.py
quit()
def leaderBoard():
import Leaderboard.py
quit()
def endGame():
quit()
答
问题是您要为所有导入语句添加.py扩展名。你只需要在文件名时,导入Python模块使
import SETTINGS
而不是import SETTINGS.py
将格式化的正确方法。
同样也适用于其他进口。
啊非常感谢你!我认为解决这个问题比这个更复杂,但它非常简单。非常感谢您的赞赏! – Feargus