Latest / CyberSecurity Summary / Create Graphical User Interfaces with Python: How to build windows, buttons, and widgets for your Python projects
Transcript
- 0:00Speaker 1: Imagine your Python code leaping off the command line, transforming
- 0:04Speaker 1: from lines of text into something truly interactive Windows buttons
- 0:07Speaker 1: images you can click, drag, and truly engage with. That's
- 0:11Speaker 1: the leap we're making today exactly.
- 0:13Speaker 2: This deep dive is all about bringing your Python programs
- 0:16Speaker 2: to life with graphical user interfaces or GUIs, and we're
- 0:20Speaker 2: going to explore GUI zero, a fantastic library specifically designed
- 0:24Speaker 2: to make GUI creation surprisingly accessible even for complex applications.
- 0:29Speaker 1: Okay, great, and our mission here is to pull out
- 0:32Speaker 1: the most practical insights maybe some surprising facts too, from
- 0:35Speaker 1: our source material, the Guide to GUE zero by Laurasak
- 0:38Speaker 1: and Martin o Hanlin from Raspberry Pie Trading. We want
- 0:41Speaker 1: to show you how easily you can actually start building
- 0:42Speaker 1: interactive apps, even games, and maybe touch on some deeper
- 0:46Speaker 1: design ideas gu zero brings up. So let's dive in.
- 0:49Speaker 1: Sounds good. We all use GUIs constantly, right, every app,
- 0:52Speaker 1: every website. But maybe let's start with the basics. What
- 0:55Speaker 1: is a graphical user interface fundamentally and what makes Zero's
- 0:59Speaker 1: take on it well different? Right?
- 1:01Speaker 2: So, a GUI is basically the visual front end of
- 1:04Speaker 2: your software. Everything you see and click, Windows buttons, text images.
- 1:08Speaker 2: It's how you talk to the software without typing commands.
- 1:11Speaker 2: What's really interesting about giezero though, is its origin story.
- 1:15Speaker 2: It wasn't some big corporate project. It was actually born
- 1:17Speaker 2: on a long train journey, a side project by a
- 1:20Speaker 2: secondary school teacher who just thought there has to be
- 1:23Speaker 2: an easier way for students to make GUIs and python.
- 1:26Speaker 1: A train journey project. That's quite something, And this idea
- 1:29Speaker 1: of it being simple but flexible that sounds really appealing.
- 1:33Speaker 1: Does that mean it's just for beginners or can it
- 1:36Speaker 1: grow with you?
- 1:36Speaker 2: Oh? It absolutely scales. It's fantastic for beginners and teachers. Yeah,
- 1:40Speaker 2: because it removes a lot of the initial hurdles. But
- 1:43Speaker 2: it's simplicity is also a benefit for experts need a
- 1:46Speaker 2: quick visual interface for a script prototyping. It's great for
- 1:49Speaker 2: that too. The whole idea is to add that spark
- 1:51Speaker 2: of excitement, as they put it, to turn simple text
- 1:54Speaker 2: output into something who colorful and interactive. And it's open source,
- 1:59Speaker 2: which is important a lot thanks to community contribution.
- 2:01Speaker 1: Okay, powerful but approachable. I like the sound of that.
- 2:06Speaker 1: How easy is it to actually, you know, install? Is
- 2:10Speaker 1: it a headache?
- 2:11Speaker 2: No, not at all. It's actually pretty simple. If you've
- 2:13Speaker 2: got PIP set up, just PIP three install guy zero.
- 2:16Speaker 2: That's usually it. You see, Python comes with pinter built in,
- 2:19Speaker 2: which is the standard GI toolkit.
- 2:21Speaker 1: Ye.
- 2:21Speaker 2: Kinter is powerful, but it can be quite wordy. Lots
- 2:25Speaker 2: of setup.
- 2:26Speaker 1: Boy, I've bumped into that before.
- 2:27Speaker 2: Yeah. So guy zero kind of acts like a friendly
- 2:30Speaker 2: layer on top of Kinder. It hides a lot of
- 2:32Speaker 2: that complexity, like managing widget placement, the event loop, all
- 2:35Speaker 2: that stuff, so you can focus more on what your
- 2:36Speaker 2: app should do, not just the nitty greedy of drawing it.
- 2:40Speaker 2: And they even mentioned ways to install it if you
- 2:42Speaker 2: don't have admin rights, which is handy in schools or
- 2:45Speaker 2: restricted environments.
- 2:46Speaker 1: That's thoughtful. Yeah, okay, so minimal setup. What's the absolute
- 2:50Speaker 1: bare minimum code? Then, like the Hello World at guizero,
- 2:53Speaker 1: what's the core idea?
- 2:54Speaker 2: The core idea is the app widget. Every single WA
- 2:57Speaker 2: zero program starts by creating an app it as your
- 3:00Speaker 2: main window, so app app my first GUI something like that,
- 3:04Speaker 2: and then crucially, at the very end of your script,
- 3:06Speaker 2: you need app dot display. That's what makes it all appear.
- 3:09Speaker 1: App dot display, got it, That's the magic.
- 3:11Speaker 2: Line exactly, and adding text Super simple. Create a textwidget,
- 3:15Speaker 2: tell it which app it belongs to, app, and give
- 3:18Speaker 2: it the text text app text welcome. Done.
- 3:21Speaker 1: Wow, that really is concise compared to some other frameworks
- 3:23Speaker 1: I've seen. Okay, so we have text, What about making
- 3:26Speaker 1: it look nicer colors, fonts. Is that where it gets complicated?
- 3:29Speaker 2: Nope? Still pretty easy. You customize widgets by changing their properties.
- 3:33Speaker 2: Want a yellow background for the whole app? App dot
- 3:35Speaker 2: bg yields a yellow simple.
- 3:37Speaker 1: As that just app dot bg. Nice.
- 3:39Speaker 2: Yeah, And if yellow isn't specific enough, you can use
- 3:41Speaker 2: hex codes those you know hashtag fifty seven hundred things
- 3:44Speaker 2: or RGB values like two fifty five to fifteen gives
- 3:47Speaker 2: you total color control. The source mentions htmlcolor codes dot com,
- 3:51Speaker 2: which is a handy place to find those codes.
- 3:53Speaker 1: Yeah, that's a good tip. No more guessing hex codes
- 3:56Speaker 1: and textiling. Bigger fonts, different looks.
- 3:58Speaker 2: Same idea properties for a text widget, say my text,
- 4:02Speaker 2: you can do my text dot text size equals thirty
- 4:05Speaker 2: or my text dot font equals verdana. They suggest common
- 4:09Speaker 2: ones like times in your Roman verdana courier impact. Just
- 4:13Speaker 2: remember that font availability depends on the operating system, so
- 4:16Speaker 2: stick to common ones if you want it to look
- 4:17Speaker 2: the same.
- 4:18Speaker 1: Everywhere makes sense. And images like if we wanted to
- 4:20Speaker 1: build that fun wanted poster id you mentioned with maybe a.
- 4:23Speaker 2: Picture of a cat, you use the picture widget picture
- 4:26Speaker 2: app image dot png. The key tip is to save
- 4:29Speaker 2: your image file PNG or non animated jeff are best
- 4:32Speaker 2: supported right in the same folder as your Python script.
- 4:35Speaker 2: That makes loading easiest.
- 4:36Speaker 1: I'll keep it simple right now.
- 4:38Speaker 2: If you need to do more advanced stuff to the image,
- 4:40Speaker 2: like resizing or cropping before you display it, Gleazera works
- 4:43Speaker 2: nicely with the pillow library, you'd install that separately, but
- 4:46Speaker 2: just for displaying an image, picture widget is all you need.
- 4:49Speaker 2: So yeah, building that wanted poster with style, text and
- 4:52Speaker 2: a picture totally doable and quite straightforward.
- 4:55Speaker 1: Okay, so we've got the visual basics down Windows, text, colors, images,
- 5:00Speaker 1: pretty easy so far, But now how do we make
- 5:03Speaker 1: these things actually do stuff? When the user interacts clicking buttons,
- 5:06Speaker 1: typing text, that's the core of a GUI, right, event
- 5:10Speaker 1: based programming exactly.
- 5:11Speaker 2: That's where the interactivity comes in, and the main tool
- 5:14Speaker 2: for triggering actions is the push button. You create a button,
- 5:17Speaker 2: give it some text, and then use its command parameter.
- 5:20Speaker 1: This is key.
- 5:21Speaker 2: You set command equal to the name of a Python
- 5:23Speaker 2: function you've written.
- 5:24Speaker 1: AH, so command my function.
- 5:26Speaker 2: Precisely when the user clicks that button, gray zero automatically
- 5:30Speaker 2: runs my function. It handles all the background event loop
- 5:33Speaker 2: stuff for you.
- 5:33Speaker 1: Okay, let's take that spy name chooser example from the source.
- 5:36Speaker 1: You press a button, it needs to generate a random name.
- 5:39Speaker 1: How does that connect?
- 5:40Speaker 2: So you'd write a Python function, let's call it generate
- 5:42Speaker 2: spy name that picks some random words and combines them.
- 5:45Speaker 2: Then you create your button button push button app text
- 5:49Speaker 2: get name command generate spye name. Now, initially, if your
- 5:53Speaker 2: generate spy name function just prints the name, it'll show up.
- 5:56Speaker 1: In the terminal window the shell, not in my nice
- 5:58Speaker 1: GI window exactly.
- 6:00Speaker 2: That's the common hurdle. The AHA moment is realizing you
- 6:04Speaker 2: need to update a widget within the GUI. So you'd
- 6:07Speaker 2: add a text widget to your app, maybe initially blank
- 6:10Speaker 2: name display text app text. Then inside your general con
- 6:14Speaker 2: name function, instead of printing, you update the text widgets
- 6:17Speaker 2: value name display dot value in cord the news by name.
- 6:21Speaker 1: AH widget dot value. That makes sense, So you change
- 6:23Speaker 1: the property of the widget in the GUI updates itself.
- 6:26Speaker 2: Precisely and that pattern. Having a command function update the
- 6:29Speaker 2: dot value or other properties of widgets is fundamental to
- 6:32Speaker 2: making dynamic GUIs with gou zero cool.
- 6:35Speaker 1: What about getting input from the user, not just clicks,
- 6:37Speaker 1: but actual text or choices. Good question.
- 6:40Speaker 2: For freeform text entry, you use the textbox widget dot
- 6:43Speaker 2: minme textbox app. Later in a function may be triggered
- 6:47Speaker 2: by a button. You can grab whatever the user typed
- 6:49Speaker 2: using my input dot value.
- 6:51Speaker 1: Simple enough. What if I want to give them choices like.
- 6:53Speaker 2: A dropdown menu, that's the combo widget. You give it
- 6:56Speaker 2: a list of options choices combo app options red, green, blue.
- 6:59Speaker 2: You can even set a default selected value, and again
- 7:01Speaker 2: you read the user's choice using choices dot value.
- 7:04Speaker 1: Okay, textbox for typing, combo for dropdowns. What about numbers
- 7:08Speaker 1: like adjusting a setting for.
- 7:09Speaker 2: Selecting a value within a range. The slighter widget is perfect.
- 7:13Speaker 2: My slider start zero and one hundred. The user drags
- 7:16Speaker 2: it and you get the selected number from my slider
- 7:19Speaker 2: dot value. Really intuitive for things like volume, brightness or
- 7:23Speaker 2: numerical settings.
- 7:24Speaker 1: Right. These seem like really useful building blocks. The source
- 7:28Speaker 1: mentions a meme generator example that pulls these together using
- 7:31Speaker 1: a drawing widget.
- 7:32Speaker 2: Yes, the meme Generator is a great example of combining these.
- 7:35Speaker 2: The drawing widget acts like a canvas. You can put
- 7:38Speaker 2: images on it using coordinates memecanvas dot image x y,
- 7:42Speaker 2: image cat dot P and e, and draw text memancanvas
- 7:45Speaker 2: dot text xy text a canvas.
- 7:48Speaker 1: Okay, but the cool part was the real time update.
- 7:50Speaker 1: Right as you type, the meme text changes instantly.
- 7:52Speaker 2: Exactly, and that uses the command parameter again, but this
- 7:55Speaker 2: time on the textbox widgets used for the meme text.
- 7:58Speaker 2: You set the command of the textbox to a function
- 8:00Speaker 2: say draw meing. Now, every time the text changes in
- 8:03Speaker 2: that box, like every keypress, the drawming function runs.
- 8:05Speaker 1: Wow. Okay, so it's not just button clicks. Command works
- 8:08Speaker 1: on text changes too. That's powerful, it really is.
- 8:11Speaker 2: Inside drawming, you'd clear the canvas, get the current text
- 8:14Speaker 2: from the textboxes, maybe get the selected color from a combo,
- 8:18Speaker 2: the size from a slider, and then redraw the image
- 8:21Speaker 2: and the text onto the drawing canvas. This creates that
- 8:24Speaker 2: immediate feedback loop, making the application feel really responsive and alive.
- 8:29Speaker 2: It shows how you integrate text inputs, sliders, drop downs,
- 8:32Speaker 2: and drawing all together.
- 8:33Speaker 1: That's a fantastic example of combining inputs and outputs dynamically.
- 8:39Speaker 1: Very cool. All right, so we've seen how to build
- 8:41Speaker 1: things make them interactive, but sometimes seeing what not to
- 8:44Speaker 1: do is just as valuable, maybe even more so. The
- 8:47Speaker 1: source has this intriguing section on the world's worst gy
- 8:52Speaker 1: I love this idea. What can we learn from well
- 8:55Speaker 1: terrible design?
- 8:56Speaker 2: It's a brilliant way to highlight usability principles. One major
- 8:59Speaker 2: pitfall they show is readability. Imagine dark green text on
- 9:02Speaker 2: a dark green background. You literally can't read it, so
- 9:05Speaker 2: less than one contrast is king Your text needs to
- 9:08Speaker 2: be clearly visible against its background. Obvious maybe, but easily overlooked.
- 9:12Speaker 1: Yeah. I've definitely seen websites like that. Okay, what else
- 9:14Speaker 1: makes a ji the worst?
- 9:16Speaker 2: Flashing text or text that just disappears after a second.
- 9:19Speaker 2: It's incredibly annoying and makes it impossible to actually process
- 9:22Speaker 2: the information. GUA zero actually gives you the tools to
- 9:26Speaker 2: do this. Funnily enough, you can hide and show widgets,
- 9:31Speaker 2: and there's an app dot repeat milliseconds function command to
- 9:35Speaker 2: run something periodically.
- 9:37Speaker 1: Ah, so you can misuse repeat to make text blink
- 9:40Speaker 1: on and off rapidly.
- 9:41Speaker 2: Exactly you could, but you really really shouldn't for anything
- 9:44Speaker 2: the user needs to read. It shows that having powerful
- 9:47Speaker 2: tools requires thinking about the user experience. Use hide show thoughtfully,
- 9:52Speaker 2: maybe for temporary status messages, not core content.
- 9:55Speaker 1: Good point, use your powers for good. What about picking
- 9:58Speaker 1: the wrong tool for the job, like using a widget
- 10:00Speaker 1: in a really inappropriate way?
- 10:02Speaker 2: Oh yeah, they have some great examples. Imagine trying to
- 10:04Speaker 2: set a specific date in time using a single slider.
- 10:07Speaker 2: A slider gives you a number right for time that's
- 10:09Speaker 2: often seconds since nineteen seventy I think the Unix epoch.
- 10:14Speaker 1: WHOA, Okay, So you'd get this huge number and have
- 10:16Speaker 1: to figure out the date from.
- 10:17Speaker 2: That precisely, utterly impractical. You'd use separate textboxes or maybe
- 10:21Speaker 2: combos for year, month, day, hour, minute, much clearer, much
- 10:26Speaker 2: more user friendly. Another hilarious one was using a combo
- 10:30Speaker 2: drop down for every single letter to type a word.
- 10:33Speaker 2: Can you imagine click select H, click select E click.
- 10:37Speaker 1: Oh my god, that's brilliantly terrible. It really hammers home
- 10:40Speaker 1: the point. Choose the widget that actually fits the task
- 10:43Speaker 1: and the user's natural workflow.
- 10:45Speaker 2: Exactly, and the final horror dot pop up overload. Quizero
- 10:49Speaker 2: has built in pop ups dot app dot info, app
- 10:51Speaker 2: dot error, and app dot Yes.
- 10:52Speaker 1: No. For confirmations, it can be useful, right like, are
- 10:55Speaker 1: you sure you want to quit?
- 10:56Speaker 2: Definitely useful for important confirmations or critical errors. But the
- 11:00Speaker 2: worst gy example might pop up a confirmation box for
- 11:04Speaker 2: every single button click You click the button, okay, button
- 11:06Speaker 2: press confirmed? Okay, It would drive anyone insane.
- 11:10Speaker 1: Yeah, use pop up sparingly for things that really need
- 11:13Speaker 1: confirmation or urgent notification.
- 11:15Speaker 2: Right, Let the user get on with their task otherwise. Now,
- 11:17Speaker 2: sometimes you do need more than a simple pop up,
- 11:19Speaker 2: maybe a whole separate settings dialogue or something good. Point
- 11:22Speaker 2: what then that's where the window widget comes in. It
- 11:24Speaker 2: lets you create entirely new separate windows, almost like mini apps.
- 11:28Speaker 2: You can put any widgets you want in them, give
- 11:30Speaker 2: them titles and control when they show or hide. Much
- 11:33Speaker 2: better for complex subtasks than trying to cram everything into
- 11:36Speaker 2: one window or using endless pop ups.
- 11:39Speaker 1: Okay, that makes sense when it for more complex site interactions. YEA,
- 11:42Speaker 1: good to know. All right, Let's switch gears a bit.
- 11:44Speaker 1: We've talked building blocks, interaction, even bad design. Now for
- 11:47Speaker 1: the really fun stuff games, The source suggests building games
- 11:51Speaker 1: is a great way to learn GUI programming and apply logic.
- 11:55Speaker 1: Let's start with a classic tic tac toe or nts
- 11:58Speaker 1: and crosses. How would Guy zero handle that?
- 12:01Speaker 2: Tic tac toe is a perfect fit. You'd likely use
- 12:04Speaker 2: a box wedget as a container for the board, and
- 12:06Speaker 2: inside that box you'd use a grid layout. Think of
- 12:08Speaker 2: it like a spreadsheet grid. Instead of manually creating nine buttons,
- 12:12Speaker 2: you can use nested loops like for x and range three,
- 12:15Speaker 2: for y and range three to create each push button programmatically.
- 12:18Speaker 2: In the loop, you assign each button it's grid x
- 12:21Speaker 2: y position. Much cleaner than nine separate button definitions.
- 12:25Speaker 1: That's clever. Using loops to build the grid saves a
- 12:28Speaker 1: lot of typing and the game logic tracking x's and
- 12:34Speaker 1: o's whose turn it is, checking for a winner.
- 12:36Speaker 2: Okay, so for the board state, a common way is
- 12:39Speaker 2: a two D list in Python, maybe initialized with none
- 12:42Speaker 2: for empty squares board none none none no no no none.
- 12:47Speaker 2: When you create the buttons in the loop, you'd set
- 12:49Speaker 2: their command to a function. Let's say square clicked. But crucially,
- 12:53Speaker 2: you need to tell that function which square was clicked.
- 12:55Speaker 1: Ah, right, how do you pass that info?
- 12:57Speaker 2: You can use the ARGs parameter in the push button.
- 12:59Speaker 2: So man square clicked arcs x Y. Now when a
- 13:02Speaker 2: button is clicked, the square clicked function receives the x
- 13:04Speaker 2: and y coordinates inside square click. You check whose turn
- 13:07Speaker 2: it is using a global turn variable maybe x or oh,
- 13:11Speaker 2: update the button's text and maybe disable it. Update your
- 13:13Speaker 2: two D board list, check for a win and switch
- 13:15Speaker 2: the turn.
- 13:16Speaker 1: Okay, that arcs parameter's handy, and the global variable for
- 13:19Speaker 1: whose turn it is?
- 13:21Speaker 2: Any pitfalls there, just the standard Python global new ones.
- 13:25Speaker 2: If your function only modifies a property of a global object,
- 13:28Speaker 2: like changing statistics dot value, you usually don't need the
- 13:32Speaker 2: global keyword inside the function. But if you need to
- 13:34Speaker 2: reassign the global variable itself, like turn avo when it
- 13:38Speaker 2: was x, then you do need global turn at the
- 13:41Speaker 2: start of that function. It's a common thing that trips
- 13:42Speaker 2: people up.
- 13:43Speaker 1: Good reminder and checking for a win. Is there an
- 13:46Speaker 1: elegant way?
- 13:47Speaker 2: Huh? The source it meets. The easiest way is often
- 13:50Speaker 2: just hard coding it check all three rows, all three columns,
- 13:53Speaker 2: both diagonals, is rozerol, all x is column one all. Oh.
- 13:57Speaker 2: It's not pretty, but for tic tac toe it's often
- 13:59Speaker 2: the simplest to write and understand.
- 14:01Speaker 1: Fair enough, sometimes simple as best. What about a draw
- 14:04Speaker 1: or resetting the game?
- 14:06Speaker 2: For a draw, you'd probably count the moves made. If
- 14:08Speaker 2: nine moves are made and no one has won, it's
- 14:10Speaker 2: a draw. A reset button would need a function that
- 14:12Speaker 2: clears the two d list back to mess none, resets
- 14:15Speaker 2: the button text and enables them again, resets the turn variable,
- 14:18Speaker 2: maybe hides a U win message. Careful state management is
- 14:22Speaker 2: key there.
- 14:22Speaker 1: Okay, Tic tac toe sounds very doable. What about destroy
- 14:25Speaker 1: the dots the waffle game that uses a different widget, right.
- 14:29Speaker 2: Yes, the waffle widget. It's specifically designed for these kinds
- 14:32Speaker 2: of grid based games or visualizations. It's basically a grid
- 14:36Speaker 2: of cells which can be different colors, and in this game,
- 14:39Speaker 2: some cells become dots. The aim is simple click the
- 14:43Speaker 2: dots to destroy them, but new dots appear over time.
- 14:47Speaker 2: If the whole grid fills with dots, you lose.
- 14:50Speaker 1: So it's dynamic. Things are changing on their own. How
- 14:52Speaker 1: does it handle the random dots appearing?
- 14:54Speaker 2: It uses random dot randent to pick random xy coordinates
- 14:57Speaker 2: on the waffle grid, and the timing RelA on that
- 15:00Speaker 2: app dot after milliseconds function method we mentioned earlier. You'd
- 15:04Speaker 2: have a function, say adot that picks rand, importants and
- 15:07Speaker 2: changes that sells color on the waffle board. App dot
- 15:09Speaker 2: set pixel x y red. Then at the end of
- 15:12Speaker 2: add dot, you'd schedule it to run again after a delay.
- 15:15Speaker 2: App dot after speed add hot. This creates the continuous
- 15:18Speaker 2: spawning of dots. Uh.
- 15:20Speaker 1: App dot after creates the game loop potentially, Yeah, clever,
- 15:23Speaker 1: and you mentioned speed. Can you make it harder? Absolutely?
- 15:26Speaker 2: You track a score every time the player clicks a dot.
- 15:28Speaker 2: The waffle widget also has a command that can be
- 15:30Speaker 2: set to handle clicks passing the clipped x y you
- 15:33Speaker 2: increase the score. Then you can adjust the speed variable
- 15:36Speaker 2: based on the score. Maybe speed equals in thousands score ten.
- 15:39Speaker 2: So the higher the score, the lower the delay, and
- 15:41Speaker 2: the faster the dots appear. Adds a nice difficulty curve.
- 15:44Speaker 1: Nice and game over.
- 15:46Speaker 2: You'd check if all the cells on the waffle are
- 15:48Speaker 2: now dots. If so, you stop the app dot after loop,
- 15:51Speaker 2: maybe with a flag and display a game over message
- 15:54Speaker 2: using a text switchet. Oh and a quick best practice
- 15:56Speaker 2: they mentioned use constants define grid size at the top up,
- 16:00Speaker 2: then use grid size everywhere instead of just typing ten
- 16:03Speaker 2: makes the code way easier to read and change later.
- 16:05Speaker 2: If you want a bigger or smaller grid, avoid those
- 16:07Speaker 2: magic numbers.
- 16:08Speaker 1: Good tip constants are always helpful. Okay, so Waffle handles
- 16:12Speaker 1: grid games well. The source also mentioned flood It and
- 16:15Speaker 1: Emoji Match briefly. What do they show?
- 16:18Speaker 2: Flood It is another Waffle based game, but more puzzle oriented.
- 16:22Speaker 2: You start at one corner and have a limited number
- 16:24Speaker 2: of moves to flood the whole grid with a single
- 16:26Speaker 2: color chosen from a palette. It introduces recursion with the
- 16:30Speaker 2: flood function logic. Emoji Match is different. It's a matching game.
- 16:35Speaker 2: It shows loading external assets like actual emoji image files,
- 16:38Speaker 2: using Python's aues module to find files and random dot
- 16:42Speaker 2: shuffle to.
- 16:42Speaker 1: Mix them up, so loading your own pictures into the
- 16:45Speaker 1: game exactly.
- 16:46Speaker 2: It uses two box containers with grid layouts. One shows
- 16:49Speaker 2: pictures of emojis, the other show's corresponding buttons. Each round,
- 16:53Speaker 2: it picks random emojis, puts one matching pair between the
- 16:56Speaker 2: pictures and the buttons, and the player has to click
- 16:58Speaker 2: the button matching one of the displayed.
- 17:00Speaker 1: Pictures, and it has a time or too.
- 17:01Speaker 2: You said, yeah, It uses app dot repeat one thousand
- 17:04Speaker 2: reduced time similar to app dot after, but repeat keeps
- 17:07Speaker 2: running automatically every second, perfect for a countdown timer if
- 17:09Speaker 2: the timer runs out. Game over hide the widgets. It
- 17:13Speaker 2: demonstrates handling assets, matching logics, scoring, and timers. Quite a
- 17:17Speaker 2: comprehensive little game example, all within GA zero.
- 17:20Speaker 1: It really shows the range from simple board games to
- 17:23Speaker 1: timed puzzles with external graphics. Very impressive. Okay, we've seen
- 17:28Speaker 1: guy zero for basics for games, but what about pushing
- 17:32Speaker 1: it further, like really advanced stuff. A paint application sounds complex?
- 17:37Speaker 1: Can Gie zero handle that level of interaction?
- 17:39Speaker 2: Surprisingly well? Yes, The paint appallies heavily on the drawing
- 17:43Speaker 2: widget again, but uses more specific mouse events instead of
- 17:46Speaker 2: just a general quick command. You can hook into things
- 17:49Speaker 2: like drawing canvas when mouse dragged equal draw dot or
- 17:52Speaker 2: drawing canvas when left button pressed equal start line.
- 17:55Speaker 1: Ah, so much finer control over mouse actions dragging versus
- 17:59Speaker 1: just clicking.
- 18:00Speaker 2: So when mouse dragged could call a function that gets
- 18:02Speaker 2: the mouse events X and y coordinates and draws a
- 18:05Speaker 2: small dot or circle there, creating a free hand line
- 18:08Speaker 2: as you drag. When left button press could store the
- 18:10Speaker 2: starting coordinates for drawing.
- 18:11Speaker 1: Shapes, and you mentioned dynamic shapes earlier, like rectangles that
- 18:15Speaker 1: grow as you drag. How does that work without leaving trails?
- 18:18Speaker 2: That's a neat trick when the mouse is dragged. When
- 18:21Speaker 2: mouse dragged while drawing a shape, the function would first
- 18:24Speaker 2: delete the previously drawn temporary shape. You can give shapes
- 18:27Speaker 2: tags or IDs to manage them, then get the current
- 18:30Speaker 2: mouse coordinates, and then draw the new larger shape from
- 18:33Speaker 2: the stored start point to the current point. It happens
- 18:37Speaker 2: so fast it looks like the shape is smoothly resizing
- 18:40Speaker 2: only when you release the mouse button. When left button
- 18:43Speaker 2: released does it draw the final shape and stop deleting
- 18:47Speaker 2: the drawing which it can handle lines, rectangles, ovals, triangles, polygons.
- 18:51Speaker 1: Wow. Okay, drawing and deleting rapidly to simulate resizing. That's clever.
- 18:56Speaker 1: And presumably you can add controls.
- 18:58Speaker 2: Oh yeah, you'd add combo widget to select the shape
- 19:01Speaker 2: type line, rectangle, oval, or color, and sliders for line thickness.
- 19:04Speaker 2: It really integrates all the widgets we've discussed. Plus there
- 19:07Speaker 2: are even more events like when key pressed if you
- 19:09Speaker 2: wanted keyboard shortcuts, or when MOUs enter when mice leaves
- 19:13Speaker 2: if you wanted highlighting effects when the mouse hovers over
- 19:15Speaker 2: the canvas. Lots of potential for rich interaction.
- 19:18Speaker 1: That really does sound like a proper application. Okay. One
- 19:21Speaker 1: more advanced example the stop frame animation creator. This one
- 19:25Speaker 1: connects to hardware, the Raspberry Pie camera.
- 19:28Speaker 2: It does this show's grease. Aro isn't just for on
- 19:31Speaker 2: screen stuff. It can be the front end for controlling hardware,
- 19:34Speaker 2: specifically the Pie camera module. Now for this one, the
- 19:38Speaker 2: source notes you need a slightly different install. Pick three
- 19:41Speaker 2: install Geezero images that pulls in extra libraries like pillow
- 19:45Speaker 2: needed for image manipulation.
- 19:47Speaker 1: Okay, special install for image features. What's the workflow like?
- 19:50Speaker 2: You use the Pie camera pison library to capture an image?
- 19:53Speaker 2: Breezero displays a live preview from the camera using a
- 19:57Speaker 2: picture widget, which is pretty cool. When you click a
- 20:00Speaker 2: capture frame button, it grabs the current image. But the
- 20:03Speaker 2: key is handling multiple frames to build the animation.
- 20:05Speaker 1: Right. An animation is just a sequence of pictures. How
- 20:08Speaker 1: are they managed?
- 20:09Speaker 2: It uses PIL, the Python imaging library, which Pillow is
- 20:12Speaker 2: a modern fork of. Each captured image is opened as
- 20:15Speaker 2: a PIL image object. These objects are stored in a
- 20:18Speaker 2: Python list. Let's call it frames frames dot a pend
- 20:21Speaker 2: new image object. To create the animated gift, you use
- 20:24Speaker 2: a function from pil dot frames zero dot save animation
- 20:29Speaker 2: dot gift save all true a pend images frames one
- 20:32Speaker 2: that bundles all the images in the list into one
- 20:34Speaker 2: animation file.
- 20:35Speaker 1: So seveal true and append images. Got it. That sounds
- 20:38Speaker 1: like the core mechanism and can the user control the animation? Yep?
- 20:41Speaker 2: You can add a slider to control of the duration,
- 20:43Speaker 2: how many milliseconds each frame is displayed in the final gift,
- 20:47Speaker 2: and very usefully a delete last frame button. Its command
- 20:50Speaker 2: would just call frames dot pop remove the last image
- 20:53Speaker 2: added to the list. Makes editing easy.
- 20:54Speaker 1: I layout buttons, slider, preview. How do you arrange them neatly?
- 20:58Speaker 2: Again? Boxidgets are your friend here. You could have a
- 21:01Speaker 2: horizontal box the top holding the captured delete save buttons,
- 21:04Speaker 2: the duration slider, and maybe a text widget showing the
- 21:06Speaker 2: frame count. Then the main picture widget for the preview
- 21:09Speaker 2: below that keeps it organized.
- 21:11Speaker 1: Makes sense? Any pro tips for making good animations this way?
- 21:15Speaker 2: One really important one they mentioned is consistent captures. If
- 21:18Speaker 2: your camera is on auto settings, auto white balance, auto exposure,
- 21:22Speaker 2: the lighting and colors might change slightly between shots. This
- 21:26Speaker 2: can cause annoying flickering in the final animation. So the
- 21:29Speaker 2: tip is to fix the camera settings like shutter speed, ISO,
- 21:33Speaker 2: white balance mode before you start capturing frames. That way,
- 21:37Speaker 2: each frame is captured under identical conditions.
- 21:39Speaker 1: Ah, lock down the camera settings. That's a great practical tip. Wow,
- 21:44Speaker 1: we've really journeyed through Guy zero today, from the absolute
- 21:48Speaker 1: basics just getting a window and some text up all
- 21:50Speaker 1: the way to well complex interactive games, a full paint program,
- 21:54Speaker 1: even controlling a camera to make animations. It's genuinely remarkable
- 21:58Speaker 1: how this library, born out of Knee for classroom simplicity
- 22:01Speaker 1: can stretch to cover such a wide range. It really
- 22:03Speaker 1: feels like a shortcut to creating quite powerful visual tools
- 22:06Speaker 1: in Python.
- 22:07Speaker 2: It really does. I think the key is how well
- 22:10Speaker 2: it abstracts away the underlying complexity of GUI toolkits like tinter.
- 22:14Speaker 2: You get to think more about your applications, logic and
- 22:17Speaker 2: the user's interaction, less about the boilerplate code just to
- 22:20Speaker 2: draw a button, whether it's that simple Hello World, or
- 22:23Speaker 2: the dynamic updates and the meme generator, or the event
- 22:26Speaker 2: handling and paint, or the hardware link for the animation tool.
- 22:30Speaker 2: That core philosophy of simple but flexible holds up surprisingly well.
- 22:34Speaker 1: So wrapping this up for everyone listening, what's the big takeaway?
- 22:37Speaker 1: The power really seems to be in your hands now
- 22:39Speaker 1: you've got these insights, these examples. Maybe the question to
- 22:42Speaker 1: ponder is what creative, maybe even surprising ways could you
- 22:47Speaker 1: use a simple GUI to bring one of your Python
- 22:50Speaker 1: scripts to life? How could you make something you've built
- 22:52Speaker 1: more accessible, more visual, more engaging for other people or
- 22:55Speaker 1: even just for yourself. With GA zero, it seems like
- 22:57Speaker 1: getting started is easier than you might think. The potential
- 23:00Speaker 1: is definitely there.