Alec.W
September 8, 2022, 2:48pm
1
im trying to make it so that when i click a button a text box appears
im just new to coding generally and struggling
from ._anvil_designer import Form1Template
from anvil import *
class Form1(Form1Template):
def init (self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
def button_1_click(self, **event_args):
self.message_label.text = 'Hello, ’ + self.name_box.text
pass
def button_1_show(self, **event_args):
“”“This method is called when the Button is shown on the screen”“”
pass
self.col_box.visible = false
def btn2_click(col_box.visible = true)
python
please help
Unfortunately, the Forum has mangled your code’s indentation, so it’s not clear what’s going on. To prevent that, put
``` python
on a line by itself before your code, and
```
on a line by itself after your code. Then we’ll have more clues to follow.
Edit: also, please be specific about
the steps you’re following,
what you expect to happen, and
what happens (or doesn’t happen) instead.
2 Likes
Hi and welcome!
So, imagine that you open your form with the text box not visible, so perhaps in your init you might have:
self.mytextbox.visible = False
Then you might have a click event on your button, like:
def mybutton_click(self,**args):
self.mytextbox.visible = True
And that’s it really!
1 Like
Alec.W
September 9, 2022, 9:41am
4
thank you james, however the event to make the box appear again is not working i have changed the names to match that of my names, but the box will not show when i run the app
Hello and welcome @Alec.W !
If you would like to have the button set up so, whenever you click it, it changes the text_box’s visibility, then here is an example:
def button_1_click(self, **event_args):
"""This button changes the text_box_1 visibility status"""
self.text_box_1.visible = False if self.text_box_1.visible else True
If you are still having problems, then please share a clone of your app, so we can have a better understanding.