I have created some Python code which is really complicated but it basically asks for an input and then outputs a huge DNA sequence depending on the input given, along with some graphs and many equations. I would like to embed this code into the user interface that I will most likely make with wxPython or Tkinter. I don’t understand how to plug my code into the user interface. Please Help! Thanks!
I have created some Python code which is really complicated but it basically asks
Share
The GUI will be handling both your input and output. So if your code is currently a big, long script that reads from and writes to the console, the first thing you’ll want to do is refactor it into a class or set of standalone functions (depending on your code) that take the input as arguments, and return the results. If you write it properly, you can even keep your console application while making the class or functions available for other applications to import.
Pseudocode example:
You may already know this, but the code inside
if __name__ == '__main__':will only be executed if you run the module directly. If you insteadimport stufffrom another module (like your GUI code), you’ll just have access to the definition of thestuff.StuffDoerclass.Here’s an example of what happens in the GUI code. Upon some interface event like clicking a button, you will call a function that retrieves the input from some fields on your form, gives them to an instance of
StuffDoer, and calls whatever class functions you need to generate your results. If there were no problems, you update the form with the generated results, and you’re done. The details of how to do that depend on your GUI toolkit.Your GUI doesn’t need to know how DNA sequences are calculated, and your DNA sequencing module doesn’t need to know where the input comes from or how the output is displayed.