有没有办法可以在 Kivy 应用程序中同时运行 Kivy 和 Flask?此外,我需要该应用程序,因此一旦您单击 Kivy 应用程序中的按钮,就会触发启动 Flask 网页的功能。然后,使用Python内置的webbrowser模块,我需要它在默认浏览器中自动打开网页。
运行此代码时,我没有收到任何错误。只是 Kivy 应用程序冻结并且不再响应。
到目前为止我的代码:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from flask import Flask
from werkzeug.serving import run_simple
import webbrowser
Builder.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)
不负相思意
相关分类