Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Call Background Function Using Linking Tkinter GUI to a separate Python File

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 9
    Answer it

    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**


         
        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**


        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.

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: