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

1

u/garlic_bread_thief Nov 25 '20

Do you by any chance write softwares where you make interactive GUIs like not just having text boxes, fields, labels, but also other objects? I'll be trying something advanced like that soon but not sure what module to use.

3

u/MacItaly if MacItaly: return helpful / else: return to_Google Nov 25 '20

So my program utilizes multiple types of windows, and PySimpleGUI offers flexibility in how your GUI looks. What types of objects are you looking to use?

1

u/garlic_bread_thief Nov 25 '20

Like graphs. The user should be able to click on the graph and my program should read from the graph to do further calculations.

2

u/MacItaly if MacItaly: return helpful / else: return to_Google Nov 25 '20

I use matplotlib to generate graphs. If it's a static plot, matplotlib allows you to trace lines for (x, y) values. You could also embed the matplotlib plot into a PySimpleGUI window with buttons along the side that, when clicked, would do whatever calculations you're referring to.