Home > Software design >  How to add a new .py file using Tkinter & Python
How to add a new .py file using Tkinter & Python

Time:12-14

I want to create a button in a GUI and attach a function to it.

The function should include some code that duplicates a python file and pass some arguments to it.

Also, I want all of the created python files (after clicking the button) to be displayed in one window and arrange them using the built-in .grid() tkinter function.

Is this possible?

CodePudding user response:

So, thanks to the comments I was able to figure out another way to achieve what I wanted.

I used a JSON file to store a list of data (different names). The data will be added to the JSON file through an entry field and a submit button.

Then a block of code will be executed for each name in a form of a loop. The code will display a set of widgets for each name and will be sorted using .pack().

NOTE: To prevent the widget functions from interrupting the other widgets mechanism (since it is a repeating of the same code), I have attached each name from the JSON file to the beginning of every variable.

So instead of auto-creating multiply python files to run a unique code for each set of widgets, JSON file, and a loop solved the issue

  • Related