Beginner - how to return text to a form?

Hello,

I’m trying to build a minimal ‘proof of concept’ form.

The idea is three items that are randomly chose from three lists. The text for that item appears on the form. If you press the button by that item, they are re-chosen.

I can return the text to the ‘output pane’ using print. I’ve done the ‘todo list’ tutorial, but I don’t really want to create a huge datatable merely to return the text. I don’t need memory between sessions or a scrolling down list of previously generated combinations.

I want the form to stay graphically static without popups, so not able to use the alert() option

Binding the returned string to a label does not seem to work either.

Any ideas?
Pat

A simple way is to place a label on the form, then set the text property, for example :

label_1.text = "Thing to display"
2 Likes

@patbrry and for the interactive bit of your question, you could set a button’s click event to trigger a function that makes your random selections and pipes the text to the labels on your form as @david.wylie suggested.

In the IDE, write a function name in the “events” pane (or just click the arrow and Anvil will set one up for you).

sc

Just for the sake of example, if your lists are contained in text boxes on your form, then to randomly choose from each list via a button click, something similar to this could work.

import random
.
.
.
def button_1_click(self, **event_args):
.
.
.
    a,b,c=[random.choice(x) 
             for x in [list_1,list_2,list_3]]
    
    self.label_1.text=a
    self.label_2.text=b
    self.label_3.text=c

Here’s an app to demonstrate.
https://anvil.works/build#clone:BIABF2DHRSOQMELT=Q3PVHD3OG7DNWENE5EBUXNRQ

Imgur

Hopefully this gets you started!

Al

1 Like

2 posts were split to a new topic: Design data loss