I am trying to make it possible to import modules for my program. In this code I've received all files but when I try to import the variables, it returns an error.
I don't want to hardcode the import in the code, I want to be able to add new python files without having to manually add them to the code. See the loadCommandFiles()
function to see what I tried.
main file:
import tkinter as tk
import os
def main():
global main_entry
main_entry = tk.Entry(font = ("Helvetica", 30, "bold"))
main_entry.pack()
main_entry.focus_set()
main_entry.bind('<Return>', entry_parser)
def entry_parser(dontCare):
entry_string = main_entry.get()
def loadCommandFiles():
for file in os.listdir(os.getcwd()):
if file.endswith(".py"):
if file.endswith("jarvis.py") == False:
exec("import {}".format(file.replace(".py", "")))
print(basicCommands.commands)
terminal = tk.Tk()
terminal.overrideredirect(True)
terminal.geometry("+{}+{}".format(int(terminal.winfo_screenwidth()/2 - terminal.winfo_reqwidth()/2), int(terminal.winfo_screenheight()/2 - terminal.winfo_reqheight()/2)))
loadCommandFiles()
main()
terminal.mainloop()
basicCommands.py
commands = ["schnitzel"]
error:
NameError: name 'basicCommands' is not defined