How to run a Python file on button click in tkinter?

Question:

I am having a Python page named Home.py and it is containing a button named View Reports. When I click this button I want another Python page named Reports.py to get executed. I developed the UI using tkinter.

Asked By: user8717954

||

Answers:

Try the below code. Works for me.

def RunWrapper():
    wrapper = ['python', 'Reports.py']
    result1 = subprocess.Popen(wrapper,  stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    out1, err1 = result1.communicate()
    status_wrapper=out1.decode("utf-8")
    tkinter.messagebox.showinfo("Execution of script is done")

Button.configure(pady="0",text='''Execute''',command=RunWrapper)
Answered By: Python Bang
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.