I'm trying to build a simple tkinter GUI window around my flask application for noobs in my office. I want the script to perform these tasks in the following order:
- Start the flask web server
- Open a tkinter GUI window with one button. When pressed, that button opens the app's index page (e.g. http://127.0.0.1:5000)
- Terminate the flask web server when the tkinter gui window is closed
This is what I have so far but the app runs independently of the tkinter window and I must terminate the flask app using crtl+c before I even see the gui window:
from flask_app import app
from tkinter import tk
import webbrowser
class GUI:
def __init__(self):
app.run()
self.btn = tk.Button(root, text='Open in Browser', command:self.open_browser_tab).pack()
def open_browser_tab(self):
webbrowser.open(url='http:127.0.0.1:5000', new=2)
if __name__ == '__main__':
root = tk.Tk()
GUI(root)
root.mainloop()
So how can I run a process while the app's running?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…