Click here to Skip to main content
14,837,089 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 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 ( which opens a panel with a button and when I click the button the function X in file 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 These button should allow me to input three values, which should be the input to the function Y in the file 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 ( and gui file ( say


import numpy
import matplotlib.pyplot as plt
import pandas

def progX():
     df = (myfile)

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


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

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)
        def create_panel2(self):
            #create buttons
            panel2 = ...
            btn2 = Button(panel1, text="yyyyy", command=bg.progB)
    All_Entries = []
    window = Tk()
    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.
Updated 25-Dec-20 19:41pm

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.
if __name__ == "__main__"
in both programs . The use import in and save both files in same folder.
try one small demo first with a simple GUI

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