Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having problem with having a GUI interface to be implemented via a second file which just contains the file to read, plots made and some new functions to be evaluated based on that.

I am trying to create a GUI application using Tkinter. The way I am doing is as follows. I have a background script (say Background.py) which has two functions. Function X loads a data file, does some calculations and outputs a graph. The way I want to trigger this is via a GUI script in another file (GUI.py) which opens a panel with a button and when I click the button the function X in file Background.py should be evaluated and a plot should be shown. Once I check the plot, I can hit another button to close the plot and terminate the function X. Now I can choose to click another button to trigger the function Y in the file Background.py. These button should allow me to input three values, which should be the input to the function Y in the file Background.py. Once I hit this button, it should trigger the function Y and do what it it asks it to do. Now at the end, after that I can hit the button to close the gui.

How can I do this?. A general rough idea will be helpful.

I have put an example as much as I can:( at least the skeleton of the code)
I have a background file say (Background.py) and gui file ( say GUI.py)

**Background.py**

Python
import numpy
import matplotlib.pyplot as plt
import pandas

def progX():
     df = pd.read (myfile)

     ##df.stats # doing something and generating a plot from the file

    plt.boxplot(df['col'])

    plt.show()

def progY(y1, y2,y3):

    ## get the y1, y2, y3 from the GUI interface which the user has entered

    #run a code...  and generate an output file

**GUI.py**
Python
import Background as bg   
    from tkinter import *
    from tkinter.ttk import *
    
    class GUI ():
        
        def create widgets(self):
            #....
        
        def create_panel2(self):
            #create buttons
            panel1 = ...
            btn1 = Button(panel1, text="yyyyy", command=bg.progA)
            btn1.pack() 
        
        def create_panel2(self):
            #create buttons
            panel2 = ...
            btn2 = Button(panel1, text="yyyyy", command=bg.progB)
            btn2.pack() 
    
    All_Entries = []
    
    window = Tk()
    D=GUI(window)
    window.mainloop()
    runprogram1 = bg.progX()
    runprogram2 = bg.probY(x, y, z)

My question is now, does the above makes sense? How can I call the background functions from the GUI? The statements runprogram1 & runprogram2 are definitely not correct, How can I implement that. Also how will I ensure that I call the proram Y in Background once I have close the output from the program X?

I guess the questions makes sense. I am new to GUI and having hard time working this out, which I need to. any help will be very much appreciated.

What I have tried:

I have tried to put the skeleton to the code.. But nothing working as of yet.
Posted
Updated 25-Dec-20 19:41pm
v3

Yes the above approach looks correct, although you seem to have different program names attached to your buttons. In general terms a GUI application starts with a blank window. It then displays information based on inputs from the user. So when you press a button (or select a menu item) it will do one of two things:
1. go straight into producing the data display as per the design, or
2. show a popup window that asks the user for some input that will affect the data that is to be displayed.
This will be repeated as long as the user presses buttons or selects menu items.
 
Share this answer
 
use
if __name__ == "__main__"
in both programs . The use import Background.py in GUI.py and save both files in same folder.
try one small demo first with a simple GUI
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900