The idea is, there are two user interfaces, one through the GUI using Tkinter , the other through the Web-API (Flask).

I wrote code that launches Flask with a login function and Tkinter , with buttons. The problem is that, for example, if Flask starts up first, Tkinter does not work, until it completes or kill the Flask process, after that, only control through Tkinter possible, and vice versa.

Is there a way to implement the management of both at the same time? In other words, it would be possible to manage through the usual and familiar GUI and through WPI .

  • Without information, how exactly everything described is implemented and what the interface is for, the question is not answered - andreymal
  • @andreymal is good, I'll come home and write a more detailed description. - Insider
  • In different threads / processes to run? - m9_psy
  • Alternatively, you can make two independent applications: a server using Flask, a client on Tkinter. The application on Tkinter sends HTTP requests to the server, it responds. - insolor
  • @ m9_psy in one, they should work at the same time. - Insider

1 answer 1

Here is an example on which you can launch TC and FLUSK.

 import flask import treading import Tkinter root = Tk() app = flask.Flask(__name__) #класс или функции самой программы def flask_main(): #код для фласка писать тут app.run(port=5001) #запуск лупа def tk_main(): #код для тк тут root.mainloop() #запуск лупа тк if __name__ == "__main__": flt = treading.Tread(target=flask_main) flt.daemon = True flt.start() #фоновый процесс tk_main() #основной поток 

Then there are the nuances. In root.mainloop (), blocking may occur, making it impossible to process in a flask or vice versa.

  • I will try and see what problems or not all this will bring. Thank you - Insider
  • app.secret_key = os.urandom(24) way, you forgot app.secret_key = os.urandom(24) needed for Flask - Insider
  • I haven't written much here - writing code is your task - eri
  • rather, it’s for those who face the same problem, so that they don’t forget) - Insider
  • works without a secret, it is only needed for authorization by cookie - eri