why doesn't the total price change realtime when . counter added and subtracted #1080
Answered
by
iron3oxide
bobwatcherx
asked this question in
Q&A
-
QuestionI made a shopping app. and use the buttons to increase and decrease . and when I change the counter value to a higher and lower number. but the total price has not changed. even though I've updated Code samplefrom flet import *
def main(page:Page):
price = Text(1200,size=25,weight="bold")
mycounter = Text(1,size=25,weight="bold")
totalprice = Text(mycounter.value * price.value)
def incrementbtn(e):
mycounter.value +=1
totalprice.value = mycounter.value * price.value
print("harga",totalprice.value)
print("counter",mycounter.value)
page.update()
def decrementbtn(e):
mycounter.value -=1
print("counter",mycounter.value)
totalprice.value = mycounter.value * price.value
page.update()
if mycounter.value < 1:
totalprice.value = 1 * price.value
mycounter.value = 1
print("total",totalprice.value)
page.update()
page.add(
AppBar(
title=Text("Flet Shopping",size=30,color="white"),
bgcolor="blue"
),
Column([
Image(src="assets/sale.jpg"),
Text(f"price is ${price.value}",size=25,weight="bold"),
Text("buy this clothes",weight="bold",size=25),
Row([
IconButton("remove",
bgcolor="red200",
on_click=decrementbtn
),
mycounter,
IconButton("add",
bgcolor="blue200",
on_click=incrementbtn
),
],alignment="spaceBetween"),
Row([
Text(f"total price : ${totalprice.value}"),
ElevatedButton("Pay Now",
bgcolor="green",color="white"
)
],alignment="spaceBetween")
])
)
flet.app(target=main,assets_dir="assets") Error messagedo not want to change the text total price . next to the green button ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Answered by
iron3oxide
Feb 23, 2023
Replies: 1 comment 5 replies
-
There are a lot of errors in the sample code, most stemming from the wrongful assumption that the |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
bobwatcherx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are a lot of errors in the sample code, most stemming from the wrongful assumption that the
value
of aText
could be an Integer. I will reply with a modified version shortly.