I am making a sort of OmniCode Tkinter app for all my beginner python programs.
All it does is look in my beginner-code file and produce a list of modules (just the string names for now) to be imported (using importlib.import_module()
) and executed at the press of a Tkinter button.
Two problems I'm having now are that iteratively creating and passing command=
kwargs
to each button results in all the buttons executing only the last module in the aforementioned list.
The second problem is that interacting with this last module (if I understand the errors correctly) is impossible further than the initial "Hello! this programme does xyz"
console response. It appears that after importing the module and executing, it is immediately closed, thus preventing any further interaction.
Here is my code:
Applications = [filename for filename in
os.listdir('C:/Users/****/PycharmProjects/Gui Test')
if isfile(filename)]
def OpenApp(app):
importlib.import_module(app)
def App_Buttons(_root):
i = 0
for app in Applications:
tk.Button(_root,
# width=15,
height=2,
relief='solid',
borderwidth=1,
text=str(app),
command=lambda: OpenApp(app),
font=("Century Gothic", 16),
).grid(row=4 + i,
column=0,
padx=20,
pady=15)
tk.Label(_root,
text=f'This is the description of App Name: {str(app)}',
font=("Century Gothic", 16)
).grid(row=4 + i,
column=1,
sticky='w')
i += 1