View gui after running the program

Asked by At

I wrote a code to perform training on a dataset. When I click the grade button in the GUI made in tkinter, I want the program to start training. But, when I close the gui window, the program starts the training.

I tried to stop the program execution after the gui window is closed.

from tkinter import *

from tkinter import scrolledtext

window = Tk()

window.title("Automated Essay grading System")
lbl = Label(window, text="Enter your essay here")
lbl.grid(column=0, row=0)
txt = scrolledtext.ScrolledText(window, width=40, height=10)
txt.grid(column=1, row=1, padx=10, pady=10)

def main():
    #rest of the code for training 
    btn = Button(window, text="Grade", command=main, padx=10, pady=10, )
    btn.grid(column=1, row=2)
    btn = Button(window, text="Quit",command=window.destroy,padx=10, pady=10)
    btn.grid(column=0, row=3)


if __name__ == "__main__":
    guiFrame = main()

I want a gui window to be viewed and when the user clicks the grade button, the main function needs to be called and the program must start training. When the window is closed the program execution must terminate.

0 Answers