#100DaysOfCode in Python Transcripts
Chapter: Days 94-96: Rich GUI apps in Python
Lecture: Demo: Adding Gooey to our app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now we're ready to incorporate Gooey. So, first thing we have to do is install it. Over here, we can say pip install gooey.
0:09 Now, this works fine on Windows and Mac, I've found there's a little bit of a problem with Linux. I'll show you that in a second.
0:15 But notice that it's depending on wxPython Phoenix, which is a brand new version of wxPython, a cross platform GUI thing, very nice.
0:24 The G-U-I version, and then Gooey is built upon that. So while that's installing, let's look over here.
0:30 I've noticed that there's a problem installing this, and I couldn't get it to work, so if you run these two sets of commands on Ubuntu,
0:37 at least if you're using Ubuntu, I haven't tried it on anything else, they should get everything set up and ready to go.
0:43 And then, you'll be able to work with wxPython and Gooey and so on. Without this, I couldn't get it to install.
0:49 By the way, this takes a really long time, like ten minutes or something crazy like that, so just be aware.
0:54 Here's the link for it over here in the Phoenix release, the 465. Okay, so this is all set up and ready to go, and the other thing that we want to do,
1:04 just for completeness sake, is we want to make sure this gets put into the requirements file. Partram will do that for us.
1:11 So let's say this: from gooey import GooeyParser. We're going to need that to, actually, that's basically the thing that triggers the UI.
1:18 We need this other thing, Decorator, that will let us basically say run this method, and get the parameters from it. So we'll come over and say Gooey,
1:26 I'll say Program Name, this will be Movie Search App, and we'll set the description. Search, talk, Python, Demo data for movies.
1:35 Remember, this is just the search, the movie search jacent API we've already played with. Let's change this to the Gooey Edition here.
1:44 This is the first thing, we have to put this Decorator, and the other, let's go to this get params.
1:49 Now all of this stuff, we don't need this at all anymore. What we're going to do is, we're going to create a thing called a parser.
1:55 That's going to be the GooeyParser. Then, on the parser, we're going to add a couple of arguments. This is super varied,
2:01 you could have all kinds of flexibility here, but we want to do two things. A basic search term, and well give it,
2:08 we'll say help equals the search term, or keyword, something to that effect. We want another one that's a little bit more complex.
2:17 So we'll come up here and say, dest=mode. That's going to be the name of the parameter that comes out. The widget, here's where it gets interesting,
2:25 this is a dropdown. Alright, there's a lot of different type of widgets, and our choices for our dropdown, tell PyCharm that's spelled correctly.
2:32 That's going to be by director, by IMDB code, you can just say director, IMDB code, and keyword. Okay, so we got this and then all we need to do,
2:46 actually, keep that for one more moment, we have to go over here and say args = parser.args parse args. This actually is what triggers the UI.
2:55 And then in here, this is a dictionary that contains two values, search term and mode. So we can just say return,
3:04 we return first the bottom mode and then the value. So args.get_mode, args.get_search_term. this little bit of code right here, that should do it.
3:18 Let's go ahead and run this and see what happens. So we got our new way of getting arguments through the UI.
3:23 we've got our Gooey, fingers crossed, run it. Look at that. How sweet is this? See our search term right there, and this is our search term
3:33 and our mode. So the search term is going to be Cameron again, and this time, we're going to go down it. Look, there's our director.
3:40 Oh, I already, I noticed something we did wrong. This is not going to work so much here, unfortunately.
3:45 We need to change these to understand what those are. So we could either return different values, like if the mode is director, make it D,
3:56 or we could just put these back at the top. I'll just change it up here. This was not, I was just going to search under keyword,
4:02 which is not what we wanted, alright? So this and then else it's going to fall through, but let me just fix the comments.
4:09 You know, the comments that lie. There we go, mode equals this. Alright, try again. Alright, now let's go and try to find those. Ready? Go.
4:21 Oh, well I guess you can see what an error looks like. I think, actually we don't do get. We just .mode. It's just dynamic, it's not like a dictionary.
4:30 There you go. One more time. Go. Boom. Look at that. How cool is this? That we built this Gooey application right here?
4:42 Our program exited successfully, found ten movies. These are the ones we just saw a little bit before. We can re-run it and it will run again.
4:49 That doesn't mean a whole lot, it just searched the same thing. Let's go over here and say we're now searching by keyword
4:55 for capital. Run it, and you'll see something interesting. Notice, it put the data down here, kind of on top of it,
5:01 so there's this kind of funky weird buildup, whereas if you run it again and again, you get like a history.
5:07 So this is kind of just like your terminal here, more or less. But I think it's okay. I mean, it's not going to win any design awards,
5:14 but it's definitely better than handing out a command line application to somebody who's really not into command lines.
5:21 So, a great way to sort of make your Python application more general.

Talk Python's Mastodon Michael Kennedy's Mastodon