有沒有辦法可以在 Kivy 應(yīng)用程序中同時(shí)運(yùn)行 Kivy 和 Flask?此外,我需要該應(yīng)用程序,因此一旦您單擊 Kivy 應(yīng)用程序中的按鈕,就會(huì)觸發(fā)啟動(dòng) Flask 網(wǎng)頁的功能。然后,使用Python內(nèi)置的webbrowser模塊,我需要它在默認(rèn)瀏覽器中自動(dòng)打開網(wǎng)頁。運(yùn)行此代碼時(shí),我沒有收到任何錯(cuò)誤。只是 Kivy 應(yīng)用程序凍結(jié)并且不再響應(yīng)。到目前為止我的代碼:from kivy.app import Appfrom kivy.lang import Builderfrom kivy.uix.screenmanager import ScreenManager, Screenfrom flask import Flaskfrom werkzeug.serving import run_simpleimport webbrowserBuilder.load_file('design.kv')answers = []class CalcScreen(Screen): def list_view(self): self.manager.current = "list_screen" def cround_view(self): self.manager.current = "round_calc_screen" def calculate(self): LengthVal = float(self.ids.length.text) WidthVal = float(self.ids.width.text) ThicknessVal = float(self.ids.thickness.text) FinalCalc = LengthVal * WidthVal * ThicknessVal / 144 FinalCalc = round(FinalCalc,1) answers.append(FinalCalc) self.ids.board_feet.text = str(FinalCalc)class ListScreen(Screen): def calc_view(self): self.manager.current = "calc_screen" def UpdateInfo(self): tot = 0 for num in answers: tot += num self.ids.total_board_feet.text = str(round(tot,1)) self.ids.total_boards.text = str(len(answers)) self.ids.list.text = str(', '.join(map(str, answers))) def ClearListAnswers(self): answers.clear() def printerview(self): app = Flask(__name__) @app.route('/') def home(): return f"<h1>BFCalc Printer Friendly View</h1>\n{self.ids.list.text}" run_simple('localhost',5000,app) webbrowser.open_new('localhost:5000')class RoundCalcScreen(Screen): def calc_view(self): self.manager.current = "calc_screen" def rc_calculate(self): RC_DiameterVal = float(self.ids.rc_diameter.text) RC_RadiusVal = RC_DiameterVal / 2 RC_ThicknessVal = float(self.ids.rc_thickness.text)
按下按鈕時(shí)在 Kivy 應(yīng)用程序中運(yùn)行 Flask 應(yīng)用程序
墨色風(fēng)雨
2023-08-03 17:09:33