[Question] How to include "another module" when publish using "flet publish main.py" #1197
-
Question
Code sampleimport flet
import pandas
from flet import (
Column,
Container,
ElevatedButton,
Page,
Row,
Text,
UserControl,
border_radius,
colors,
)
class CalculatorApp(UserControl):
def build(self):
self.reset()
self.result = Text(value="0", color=colors.WHITE, size=20)
# application's root control (i.e. "view") containing all other controls
return Container(
width=300,
bgcolor=colors.BLACK,
border_radius=border_radius.all(20),
padding=20,
content=Column(
controls=[
Row(controls=[self.result], alignment="end"),
Row(
controls=[
ElevatedButton(
text="AC",
bgcolor=colors.BLUE_GREY_100,
color=colors.BLACK,
expand=1,
on_click=self.button_clicked,
data="AC",
),
ElevatedButton(
text="+/-",
bgcolor=colors.BLUE_GREY_100,
color=colors.BLACK,
expand=1,
on_click=self.button_clicked,
data="+/-",
),
ElevatedButton(
text="%",
bgcolor=colors.BLUE_GREY_100,
color=colors.BLACK,
expand=1,
on_click=self.button_clicked,
data="%",
),
ElevatedButton(
text="/",
bgcolor=colors.ORANGE,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="/",
),
],
),
Row(
controls=[
ElevatedButton(
text="7",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="7",
),
ElevatedButton(
text="8",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="8",
),
ElevatedButton(
text="9",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="9",
),
ElevatedButton(
text="*",
bgcolor=colors.ORANGE,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="*",
),
]
),
Row(
controls=[
ElevatedButton(
text="4",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="4",
),
ElevatedButton(
text="5",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="5",
),
ElevatedButton(
text="6",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="6",
),
ElevatedButton(
text="-",
bgcolor=colors.ORANGE,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="-",
),
]
),
Row(
controls=[
ElevatedButton(
text="1",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="1",
),
ElevatedButton(
text="2",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="2",
),
ElevatedButton(
text="3",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="3",
),
ElevatedButton(
text="+",
bgcolor=colors.ORANGE,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="+",
),
]
),
Row(
controls=[
ElevatedButton(
text="0",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=2,
on_click=self.button_clicked,
data="0",
),
ElevatedButton(
text=".",
bgcolor=colors.WHITE24,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data=".",
),
ElevatedButton(
text="=",
bgcolor=colors.ORANGE,
color=colors.WHITE,
expand=1,
on_click=self.button_clicked,
data="=",
),
]
),
],
),
)
def button_clicked(self, e):
data = e.control.data
if self.result.value == "Error" or data == "AC":
self.result.value = "0"
self.reset()
elif data in ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "."):
if self.result.value == "0" or self.new_operand == True:
self.result.value = data
self.new_operand = False
else:
self.result.value = self.result.value + data
elif data in ("+", "-", "*", "/"):
self.result.value = self.calculate(
self.operand1, float(self.result.value), self.operator
)
self.operator = data
if self.result.value == "Error":
self.operand1 = "0"
else:
self.operand1 = float(self.result.value)
self.new_operand = True
elif data in ("="):
self.result.value = self.calculate(
self.operand1, float(self.result.value), self.operator
)
self.reset()
elif data in ("%"):
self.result.value = float(self.result.value) / 100
self.reset()
elif data in ("+/-"):
if float(self.result.value) > 0:
self.result.value = "-" + str(self.result.value)
elif float(self.result.value) < 0:
self.result.value = str(
self.format_number(abs(float(self.result.value)))
)
self.update()
def format_number(self, num):
if num % 1 == 0:
return int(num)
else:
return num
def calculate(self, operand1, operand2, operator):
if operator == "+":
return self.format_number(operand1 + operand2)
elif operator == "-":
return self.format_number(operand1 - operand2)
elif operator == "*":
return self.format_number(operand1 * operand2)
elif operator == "/":
if operand2 == 0:
return "Error"
else:
return self.format_number(operand1 / operand2)
def reset(self):
self.operator = "+"
self.operand1 = 0
self.new_operand = True
def main(page: Page):
page.title = "Calc App"
# create application instance
calc = CalculatorApp()
# add application's root control to the page
page.add(calc)
flet.app(target=main) Error messageWORKING------------------------
python -m http.server --directory dist
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
::1 - - [20/Mar/2023 17:49:19] "GET / HTTP/1.1" 200 -::1 - - [20/Mar/2023 17:49:19] "GET /python.js HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:19] "GET /flutter.js HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:19] "GET /icons/loading-animation.png HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:20] "GET /python-worker.js HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:20] "GET /favicon.png HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:20] "GET /flutter_service_worker.js?v=672402291 HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:20] "GET /main.dart.js HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:20] "GET /index.html HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:20] "GET /assets/AssetManifest.json HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:49:20] "GET /assets/FontManifest.json HTTP/1.1" 200 -
ERROR--------------------------
python -m http.server --directory dist
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
::1 - - [20/Mar/2023 17:50:26] "GET / HTTP/1.1" 200 -::1 - - [20/Mar/2023 17:50:28] "GET /app.tar.gz HTTP/1.1" 200 -
::1 - - [20/Mar/2023 17:50:29] "GET /flutter_service_worker.js?v=672402291 HTTP/1.1" 304 -
>>> NOT FURTHER ACTION >>> at HTTP/1.1 304 - ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I'm facing the same problem.... before importing pyrebase my webapp works just fine... but after implement pyrebase. it wont load at all. I think it must be the requirement.txt. before adding pyrebase the requirement.txt only content "flet==0.4.2. but after implement pyrebase. I try add "flet==0.4.2,Pyrebase4==0.4.6. but still wont works perhaps I need to add more the the requirements.txt. little help would be much appreciated. |
Beta Was this translation helpful? Give feedback.
-
In
|
Beta Was this translation helpful? Give feedback.
In
requirements.txt
it should be one requirement - one line: