Anvil: Web Apps with Nothing but Python Transcripts
Chapter: Navigating between views
Lecture: Setting the title during navigation

Login or purchase this course to watch this video and the rest of the course contents.
0:00 When we run our app it's working but notice the title up here is just the title of the app and that may be okay
0:08 but, in this example, I would like to see right now I'm on the compare page or now I'm on the add page and so on so let's go and update that.
0:17 So let's go down here for each one of these and we're going to add a separate function. Now, I could just directly work with the form
0:24 but again, I like have this nice and broken out so I have def set_title and what we're going to do is we're going to say form = get_form() and our form
0:33 if we go look at it has a self.label_title. So, labeled titles is what we want to work with and we'll say label_title, that's the control
0:44 and then we want to say the text is equal to, well what? We could just say text, right? But what we actually want to do is have the base title
0:52 plus this. So, let's go back to our home form and say something to the effect of self.base_title equals this at start up
1:02 that way we let people design it in the designer we have access to this here. So if we change up the designer we don't have to
1:09 go and change code as well. So what we will do is say base_title = form.base_title. We'll say if there's some text passed in we'll do base title.
1:30 We just want to set it to base_title. Like this. Okay, so this, I think this will do it. Now we just have to call set_title.
1:38 So here we can say set_title("Add Measurement"). Just say, for this one let's set it to just nothing, like that.
1:53 Compare. We'll have your account like that. Now, let's see if this is going to work. Form is not find. Where do we do this? Yes, it's with the self.
2:12 Okay, notice nothing appeared. We click on add. Add measurement, compare, add home goes back to nothing remember that the colon is gone.
2:22 Actually I would like to have a dash I think, but I will put that in a sec. So over here, you see how cool that is?
2:27 Now it's super easy for us to give a little bit better idea to the user on where they are. 'Cause we have this all centralized into one
2:36 beautiful place. Make one change right there. Every time it changes, every time that we navigate somewhere it's going to take that change.
2:43 That's why we refactored it. So, if we go here we're going to add, there's our dash there's our compare, there's our count, there's our nothing.
2:52 All right, looks like we're setting our title, great.


Talk Python's Mastodon Michael Kennedy's Mastodon