ParthJadhav / Tkinter-Designer

An easy and fast way to create a Python GUI 🐍
BSD 3-Clause "New" or "Revised" License
8.66k stars 797 forks source link

changing design, regeneration, and overwrites #303

Open robtbiddle opened 1 year ago

robtbiddle commented 1 year ago

I'm pleased to see the work on tkdesigner, and plan to recommend it to some friends. There is one issue I would like advice on, or perhaps a small change to request.

As it is now, the idea seems to be that after the gui.py is generated, one modifies that code to add functionality. The problem is that if one later wishes to change the design and regenerate, then the added functionality is lost. Is there a good way to deal with this?

If not, I suggest an easy way is to add the functionality in a separate file that imports gui.py E.g. import gui def dostuff(): print("Doing Stuff...")

gui.button_1.configure(command=dostuff) gui.window.mainloop()

Then the generated default functionality change be changed in the new file, and gui.py is never touched. The problem is that the default template ends with a call to mainloop(), which means this approach cannot work, because when gui is imported, any new code is ignored.

It seems to me an easy change is to change the final line in the template to this: if name == 'main': window.mainloop()

Then is someone executes gui.py directly, the functionality is the same as now. But they someone imports gui, then mainloop is not executed, and they can modify the default functionality, and call mainloop themselves.

Is this reasonable?