r/learnpython • if MacItaly: return helpful / else: return to_Google • Nov 24 '20

Beginner/Intermediate Python Programmer Finally Using Multiple Files for Project

Holy Moley! I started playing around with building a mini-project using multiple files instead of one long file. Wait, let me back up...

I just started Python about a year ago, self-taught, and have been actively building desktop apps for my company in the CMP Semiconductor field. They're efficient applications that my boss loves and have been able to make us some good $$$. But, my codes are over 10,000 lines long. And I knew there had to be a better way.

Fast forward to today where I built a main file, and put a class in another file with some basic math functions. Then in my main file I built a little GUI to solve simple math problems. (I LOVE PYSIMPLEGUI, a big shout out to u/MikeTheWatchGuy for all the work he does.) And I just imported the class into my main and called it as normal...and it works. Easy as pie. I couldn't believe it. I feel like I've just learned a super valuable piece of information that I had been missing out on. Milestone achieved.

Thanks for reading and sharing in my epiphany!

433 Upvotes

75 comments sorted by

View all comments

6

u/AlexandrTheGreat Nov 24 '20

In my quest to find a WYSIWYG GUI editor for python, I found pysimplegui which is lovely, and while it doesn't fit the original need, it does make prototyping very easy.

1

u/buttwarmers Nov 24 '20

Have you tried qt designer?

1

u/AlexandrTheGreat Nov 24 '20

I did, but it spat out weird code and IIRC it required a few hoops to jump through to use it beyond a mock-up. IIRC it also could really be updated? I tried it out a long-ish time ago

2

u/Dogeek Expert - 3.9.1 Nov 25 '20

The workflow with Qt Designer is to save the .ui file somewhere, and then use the uic command line utility to "compile" that into a python file.

That file is not intended to be used as is though, as a recompile would overwrite it. You can import it though, and make a new class that inherits from it with all the methods and signals you want/need. That way,, if you need to update the UI and recompile it, you don't lose any code.

1

u/MikeTheWatchGuy Nov 25 '20

This seems like the right way to go about using the Qt designer (or any designer), but I don't recall seeing any tutorials that follow this approach.