#326: Building Desktop Apps with wxPython Transcript
00:00 Did you know that I'm a fan of GUIs. You know, they're kind of like web pages, but they run on your computer, they have their own windows, and you can even use those applications offline. On this episode, we'll dive into wxPython with Mike Driscoll. He's back on the podcast to share his hard won experience on building and distributed Python Window based applications. This is talk Python to me, Episode 326, recorded July 14 2021.
00:39 Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter, where I'm @mkennedy and keep up with the show and listen to past episodes at 'talkpython.fm'. And follow the show on Twitter via @talkpython. This episode is brought to you by Linode & Us over at talk Python training and the transcripts are brought to you by 'Assembly AI', please check out what we're offering during our segments. It really helps support the show.
01:08 You want to learn Python, but you can't bear to subscribe to yet another service at talk Python training we hate subscriptions to that's what our course bundle gives you full access to the entire library of courses. For one fair price. That's right, with the course bundle, you save 70% off the full price of our courses, and you own them all forever. That includes courses published at the time of the purchase, as well as courses released within about a year of the bundle to stop subscribing and start learning at 'talkpython.fm/everything'.
01:41 Mike, welcome to talk Python me know. Thanks so much for having me again. Yeah, it's great to have you here. Maybe you can just remind people of the last time you are here. You wrote a really cool book called I think it was 'Python Interviews'. Is that do I have the title, correct? Yes, that's correct. Yeah. And that was back in Episode 156. Way back in 2018. like three years ago, I guess more than that. But it was a history book. So it was looking back, right. It's fine. It's still relevant. People can check that out. And I really love some of the stories that you told on there. I love. I think it was Alex Martelli. you interviewed him and talked about how Google Video and YouTube are sort of competing neck and neck. And that was sort of a Python versus C++ story. That's probably the one that stuck with me the most. Yeah, I really enjoyed that one, or that does some good stuff in the Brett cannon interview as well. Yeah, there's a great stuff all over. I'm just trying to think of the one that I remember years later, you know, yeah, yeah. So it's been a couple years since you've been on the show. What do you been up to? Well, since that book came out, I have been pretty prolific in my writing and continue to write more Python books. For example, I've written one on 'wxPython', and 'Report Lab'. I redid 'Python 101', which was my first book, and Report lab is about like working with PDFs, right. Yes, you can use it to create PDFs, edit, but that book also covers how to edit options, edit, how to read and get data out of an existing PDF as well. Yeah. You got a couple of 101 201 type books as well. Yeah, like Learning Python? Yep. Python. 101 is for beginners and 201 is kind of intermediate advanced. So if I was like, a sophomore might take that, yes. Cool. So what are you doing these days? Are you doing the independent thing with your authoring and creating? Are you doing consulting? What do you do? Oh, I still would do a full time job. I write Python code that tests an embedded C++ application with Python. Oh, nice. It's really neat. But I also you know, kind of as a hobby slash side job I write for myself, I write, I write these books. And I occasionally contribute to real Python as well. A lot of good stuff going over real Python, Dan, and crew keeps that content flowing over there for sure. Yep. Yeah, absolutely. So, we're gonna talk about building GUIs. Or GUIs as some people say them? I know I'm okay. Are you a GUI? Are you a GUI sort of person? I usually call it GUI. Yeah, me too. So we're gonna talk about those for Python, which I think is interesting, because there are a have been, there are decent options. But it's not a place where Python has traditionally received a ton of focus and energy on building a lot of these frameworks have to do with taking another framework. That's a nice cross platform framework and like making it friendly for Python, right? I'm thinking of like, yeah, cute, or even wxPython, right? Yeah, it's usually a C++ wrapper that pre existed Python, and then it got wrapped with bindings of some sort. Yeah, exactly. A lot of these, especially the ones that do native widgets. Those are really just wrappers over the operating system when doing API's, right, like WIN 32 or is it COCO on Mac OS, those kinds of things. Right. So it's like some thin layer than some adaption adapting thing for Python. Right? Yeah, I think there's only a handful that aren't wrapping.
05:00 something else like be Where's toga? I don't believe is wrapping the native. I'm trying to look at it as I guess it is wrapping in a way, but it's not wrapping a pre existing framework. Right? Right. It's probably super low level, like here is a literally create a window that has a button. And that's it like, not like cute or something cute. Yeah, I think toga is actually like, you know, trying to render the cocoa widgets or the win 32 widgets itself, you know, rather than calling like Q2 or wx. Yeah, there's some value to that there's some value to that. So I thought the place that we could start is maybe a survey of these different libraries that we could use. Sure. Right. And so let's start with Tinker 'tkinter', which is really the Python interface to TCL/TK, right. Yeah, so this one comes built in. Right. I'm here on the Python 396 documentation. And I guess this is the official way to create GUIs with Python, right. I mean, in the sense that it ships with it, it ships with it, however, on like Linux, that the system Python does not come with. Okay. So you still got and I believe, I believe Mac is the same way you have to install it separately for it's just on Python two. Yeah, that wouldn't surprise me. Well, you know, the system, Python and Mac is all sorts of outdated and yes was basically right, like 27. Who knows what, right. But yeah, but it's always surprises me when I go to import t Kenter. And it's like, oh, it's not there. Like what? Yeah, exactly. Tell us about this one. Like, what's the good side? When would use it? Or would you use it when wouldn't use it? I don't like it because it looks a little old fashioned. But mainly because it draws all its own widgets, just like some of the other GUI toolkits. So basically, when you create a T kinter GUI, you know what the tkinter because it doesn't look native. However, you can use a TK enter, the code can be written without classes, you could write it completely functionally, and still make your work. So you know, as a learning way to create a GUI, it might be a good first, you know, a good beginner our first GUI to create with. Yeah, absolutely. Yeah, I put up on the screenshot screen for us to see there's like this TKinter Hotel Management System, it definitely doesn't I didn't see the top bar. I couldn't tell you what OS that's from. But because it doesn't look like OS that I know, right? Although, there's another example. I'll put these in the show notes. There's a pretty nice one that's hosting some kind of like predates Jupyter or something like hotels matplotlib exploration and stuff. And that looks like a pretty solid app to me. Yeah. tkinter did add a sub module called TTK, which does look a lot more native across platforms. You can make it look nice actually, if you if you spend the time, but you're going to have trouble finding good examples online because a lot of them just use the old the old interface. Another one thing I do want to note about TKinter is it's themable. So if you want it to look new, you want to add themes to your, your GUI, your ticket is an option for that. Oh, interesting things. So for example, you could give it a Mac OS like theme that turns on in that platform and a Linux theme maybe mode and not dark mode. Yeah, I was thinking of dark modes light modes be giving them a certain you know, color things kind of like a win amp type of skin. Yeah. Oh, man. Remember that? How crazy those skins would get. They'd get like 3d with little holes cut in. And yeah, that stuff got that got a little drawers like an alien tongue would shoot out and that's where like the playlists don't do that people don't do that. Okay, so for the most part TK inter is built in ish least it's sort of somewhat officially part of Python, right? Yes, it is another one one that I think of a lot when I think a cross platform stuff is cute. PyQt
08:45 PyQt. There's been a lot of different versions of PyQt. They're like a lot of stuff in licensing so like right here on the homepage. It says licensing PyQt has dual license on all the platforms under GPL 3 and the riverbank commercial one. Unlike PyQt is not available under LGPL, which is I guess what you would need for like a commercial closed source app. And there's, there's another wrapper around Qt. That I think is lgpl. Like the there's a lot of stuff that's just like, Well, why is it so complicated? Yeah. PyQt is kind of confusing when it comes to its licensing structure. Yeah, she's crazy, because I've had this conversation multiple times. And it seems like it I don't know it either. It never resolves clearly in my mind, or it's just challenging. But that said, there's really nice apps built with Qt. So for example, like one of the database tools I use for working with MongoDB is Robo 3T. And if you look at Robo 3T this thing is glorious in terms of its sort of native look and feel like if you go to the robomongo.org scroll down for the screenshots. There's the three OSS, side by side and every one of them looks like it belongs on that platform, right? Yeah, you can get a little bit simpler with instead of using PyQ, you could use Qt
10:00 Python, which is the new name for Pyside, right? That's right. And it has a more permissive licensing structure as the one I was thinking of. Yes. Thank you. Yeah, they renamed that to Qt. for Python. Right, I believe. So. Although the import is still PySide. Is it so far aside? How interesting. It's like PySide6, I think. Yes. Yeah. How interesting so this, I think, due to a pretty solid option. I feel like I see Qt being used in embedded systems and other types of things. Like I said, I started using Robo Mongo, just because it seemed like a good app. And like, Oh, this is a cute app. It's not a Python is a C++ app. But it just as well could be like, there's nothing fancy about it that it makes it have to be C++. It just happens to been that way. Yeah, yeah. So what are your thoughts on this as one of the options? Oh, Qt is really powerful. You can do a, you can do a ton, and it while it draws off its own widgets itself is not actually using the native widgets. It looks native, as they say, made it frm. Yeah, again, this one is also the mobile if you want to do themes, you can change, you know, dark mode like mode easily. Because that's all drawn itself. I think.PyQt and Qt for Python, both support QML, which is kind of an XML version of a c++ Library. So you can kind of write it write your GUIs and markup and a markup language. Yeah, that's right. It's a little bit like XML or YAML. From the Microsoft space. Yeah, that's right. It also has a, what you see is what you get editor, I guess, Qt designer that works for both c++ and Python, I believe the Python side, you have to do some special imports to actually use the UI file it generates. Yeah, that seems like a really valuable thing to me to visually be able to say I want this widget to be here. I want this one to stretch like that. And so on. Yeah, I work with a bunch of c++ Qt guys. And they use the designer, but occasionally, it will do crazy things when your design gets really complex, where it's really hard to get stuff to stretch the way you want it to. And sometimes you just have to drop into the code to make it work. Right. Yeah. Well, I think that's probably the case with many other frameworks, right? Not just these Python ones we're highlighting, but you know, Xcode? Well, whatever, right? I think that's, that's what's the problem with auto generated UI code. Whenever you use a designer like that, or Visual Studio, you're going to run into quirks. Yeah. Yeah, for sure. Next up on our list here is 'Kivy'. Give me I heard about a lot from sort of building mobile apps with Python. and interesting ways. It's kind of got this game, draw your own UI sort of feel to it. Yeah. It's also a cross platform. It runs on mobile too, though. So you can you can deploy its apps to Android and Apple iOS. But yeah, a lot of the stuff on there. Well, I should back up. It was originally developed for multi touch. So like, Microsoft's original surface table, I think is what it was originally developed for. Yeah. But you know, obviously, it also works great on multi touch phones, and whatnot. But yeah, all of its widgets are drawn by kivi. itself. So they look like a kivi app most of the time. Yeah, they have a gallery over here. And in the gallery. They even have like some surface table exploration stuff like the city of marsay map exploration type thing, right? They have a kivi garden, I believe that also showcases lots of custom widgets. Yeah. So when I look at the mine scrolling through the gallery here, I feel like there's a lot of 2d sort of interactive things a lot, a lot of games or stuff like that. Right? So it's, if I wanted to build an app that maybe looked like it use the windows rich text box and the Windows button, so it looked like a I don't know, Windows 10 button on Windows 10 and a Windows 11 button with curved edges. It's not that kind of framework, right? No, it's not. And I believe kivi is based on written on top of pygame. Oh, it has that's why in the game so well, right. It sounds familiar to me as well. And apparently the winner of the Python discord Code Jam six was done in kivi. That's pretty cool. That is cool, as well as second place. So I see. Is there a third place one down here? Yeah, it is they they clean sweep of the podium with kivi. So that's pretty impressive, actually. Yeah. I've actually played one of their games on my phone before and they seem pretty well done. Nice. Another one that's gotten a lot of traction and has his own opinions for how it works is PySimple GUI. I think Mike Barnett's I'm remembering correctly is working on that. Yeah. And yeah, its idea is to make it super simple to just get a basic UI up and running. Right? Yeah. So PySimple, gooey wraps, I think four or five other frameworks. Though. It wraps TKinter wxPython PyQt. Remy, which is a mobile thing, and something else and basically gives you the same API for all of them. So that you know if you write your code once and then you just change the import from like, import pysimple GUI to import pysimple GUIqt or pi simple GUI
15:00 w x, you can get that native look and feel because you're using Oh, yeah to execute. Oh, that's a really cool aspect, right that you can swap out the widget engine or something basically. Yeah. The default is TKinter. Yeah, probably. It's the least dependencies and your think about which kind of license you're doing what with? Yes. Interesting. Okay, so this is a pretty cool one, if you're just trying to get a dialogue up, that mic has one or two buttons and an input and a progress bar, maybe this is a good option, it can do quite a bit of complex GUIs. To that there's a demo package that they have that shows how to integrate it with map matplotlib, and open CV, and lots of other things. These examples don't show the advanced stuff I can do where I am sort of paging through the gallery, the screenshot you have on the site there, which will link to and again, since it's using Tkinter, it also does themes natively, or
15:56 atleast for the killer part. Yeah, exactly.
16:00 This portion of talk Python to me is sponsored by Linode. Visit 'talkpython.fm/linode'. To see why Linode has been voted the top infrastructure as a service provider by both G2 and TrustRadius. From there award winning support, which is offered 24/7, 365 to every level of user, the ease of use and setup. It's clear why developers have been trusting Linode for projects both big and small, since 2003. deploy your entire application stack with linode to one click app marketplace, or build it all from scratch and manage everything yourself with supported centralized tools like Terraform. The Linode offers the best price performance value for all compute instances, including GPUs, as well as block storage Kubernetes. And their upcoming Bare Metal release. Linode makes cloud computing fast, simple and affordable, allowing you to focus on your projects, not your infrastructure, visit 'talkpython.fm/linode'. and sign up with your Google account, your GitHub account or your email address. And you'll get $100 in credit, as 'talkpython.fm/linode'. Or just click the link in your podcast player show notes. And thank them for supporting talk Python.
17:10 Super cool okay that's another option we got out there. When they put in a list that I haven't really done anything with is DearPyGUI, a fast and powerful graphical user interface toolkit for Python with minimal dependencies. Those about this one, this one I haven't played with very much yet. But I believe the guy who created it has been working a lot on it lately. And it has a really neat interface. I don't think it's wrapping anything. But I could be mistaken. It looks very focused on providing animated and interactive aspects for like scientific visualization and exploration. Yeah, I think it has it. I don't believe it tries to look native necessarily either. But it has a very slick interface. Yeah. Yeah, it does. There's a lot of cool stuff that's going on here. Okay, so that's a neat one. And I guess one that I didn't properly cover. Oh, yeah. Cuz I didn't pull up in our little list here. But is a 'Toga' from 'beeware'. On that, right. Yep. So, this all this of our reviewers super neat. There's a lot of nice things going on it definitely the native widgets, feels. And I just always feel kind of, like, this thing doesn't really belong here. Right. When I see an app, it just looks like you're like this is, you know, some clearly cross platform not really this platform. feel right. Yes. I don't know. I appreciate the native, which is aspects, but it's also listed in sort of the maturity level as early development. Right. So I'm not sure if this is ready for you to pick up and build with yet. Yeah, not really is my understanding. And oddly enough, it's been in early development for like the last five years. Yeah. So it's been really slow to develop. They're trying to do it from the ground up, and they're not wrapping anything, and somewhat understandable. But I think they recently added Android support. So I think that they're focusing more and more on the mobile stuff, then, you know, like Windows and Mac data warehouses. Yeah. The last commit was merged PR from Russell, Keith McGee four days ago. So there's still Yeah, yeah, they're still working on it. Alright, well, that's brings us over to the wxPython, which is another one of these options in this space. But that's what we're going to focus on in this particular episode, right? Yep. So give us the quick overview of w x Python sort of compared to these other options we've been covering. So wxPython is again, a c++ project wraps wx widgets or Wix widgets, I've heard it called. It works on Windows, Mac, and Linux and Raspberry Pi. The big thing about depicts Python is that it does do native widgets wherever possible on all platforms. So that's, that is really cool. It also provides a lot of custom widgets, in case you need them for certain purposes, like some, I believe, I think it was Mac that didn't have a toggle widget for a long time. So they provided their own toggle widget for it right. It's the GUI equivalent of a polyfill. It's like that
20:00 feature is not supported, but you want it Well, like I here's that something that'll do for now. Yeah, very cool. It looks to me like it checks a lot of the right boxes. What's the licensing story? It's very permissive the upload, they're a public repo and hit their license doc and see what I can find. I know it finally they called it the wx Python license, but I'm trying to Nah, that's right. It looks lgpl ish. Yeah, I think it is mostly lgpl. Yeah, cool. That's better than multi license. confusing, like, the C layer has one license, and the Python layer has another license. But then there's this other commercial license. So it seems like it's pretty easy for you to just decide to adopt it and use it on your project. Yeah, I would agree with that. And it is also extremely stable. They almost never break your code when they release a new version. Okay, that's cool. I heard that it rose from the ashes.
20:54 Yeah, Phoenix release, and then the legacy or traditional version. What's the story of that? Oh, yeah. So you know, Python three came out. And a lot of people, you know, fussed about supporting it. It was a pretty big deal to you to port Python, wx Python to Python3, because wx Python has a really small group of core developers. But eventually he creates a Robin Dunn is the main guy behind wx Python currently. And he decided, well, we're going to call it project Phoenix while I get this working. And I think he actually switched the way he binded to Wx widgets at the time, because he went from like swig to I believe, sip, which is a different type of binding. Okay. And that made it a lot easier to support both Python 2.7, and I think it was 3.4 was the first release for wxPython. And that also made it PIP installable. So that was super awesome. When you got that working, so. If I want to use it, I can just pip install the wxPython, or wait, as I'm learning that I might want to say it that way. Yes, that's correct. And there's a caveat on Linux that sometimes you need to have a couple of extra lindbeck Linux dependencies installed. But other than that, .pip install should work. Yeah, well, that's pretty standard. Right? If you're doing GUI stuff on Linux, modern times, like, there's elements there, you got to add doesn't seem outrageous. No. Yeah. So another thing that I'm a big fan of, to the extent that they work in the better that works, the more I'm a fan of it is the like the GUI designer. So there's two over here, right? We've got like this w x or wx Form builder in the wx Glade. I think I tried the wx form builder, and it just kept crashing, not like it would start and was unstable, that would not start for me. And I don't know what the deal maybe it was the version of Mac, or something. But what's the story? Are these are these things that people would use? Now? What's the story around the wiziwig? side of these wxPython traditionally hasn't had really, what are was your wx editor, but people have tried to build them. So I think wx Glade as part of the one that's been around the longest, okay, and probably the best supported, I don't think I think it's a part of the core widgets of wx Python. If you were to pull up the wx Python demo app, there are like 100, I would say at least 100 widgets, maybe more, maybe 200. So the core widgets, you know, like buttons that I find that under widgets are going to find that under me see downloads there you go unfortunately, it's actually something you run. Yeah, sure, sure. So you can download I think I have run that before. And you basically it's like all these windows that will show you little use cases for this widget or that widget, right? That also shows you the code and you can edit the code live in the demo and see how it how it changes the widget. Oh, that's a it does a decent enough job. I think it outputs a Python file. So that's nice. It doesn't put you know, like Qt designer outputs a UI file that you have to figure out how to import and then use that's when actually outputs right Python file. Oh, that's nice. Yeah, that's really good. So I'm looking at the screen here. And it looks like audacity, though well known audio audio editing app is built in wx guessing otherwise, there's no reason they would feature it. I believe that's true. I'm not sure if it's wx widgets itself. Yeah, it's on the Wx widgets site. And I'm pretty sure to see their thing. But yeah, these are, these are pretty good looking apps that you can like sort of page through all their screenshots on just Wx widgets.org. Almost even like an auto trader looking thing. And like a diff tool. File merge. Yeah. bassetti. Yeah, I believe one of the Linux diff tools is written with w x Python. And I had heard that the dropbox UI was written with w x for a while I don't know if it still is or not, though, so it seems like there's quite a rich library for working with these things with wx. I thought, wx, Python. And I guess you may maybe one of the nice ways to explore this would be Am I gonna go over here a little bit to talk about sort of some of the things you covered in a recent book that you wrote, not super reason, but somewhat recent, Creating GUI applications with wxPython, which is pretty cool.
20:54 'balsamiq' as something where you could potentially sketch out the UI. Yeah, I really liked balsamic because it just makes it makes laying stuff out a kind of a breeze. You could also, you know, you could use that cube designer because it's free and open source, you could use that to a draw layout to it right, even though your destination is not ultimately cube. But it still lets you draw or dragging the widgets around. Right? Yeah. So you can still get a good idea of what you want to look like using that. Yeah, I guess if you had a really old version of Visual Basic laying around, yes. I also worked. I thought about that. The VB 6 I mean, that thing went out of support, like in the 90s. But you might get it run. But yeah, the balsalmiq one, I really like this. I've used this for prototyping a couple of things. I think I use it a lot when I was building the talk Python training platform, and stuff like that. It's it's one of these wirey wireframe type of tools that like specifically is not meant to look native or finished. Right? Kinda looks as if you had drawn it by hand like the web browser. It's sort of wiggly lines as if you'd Yes, get to that. All right. I like this thing a lot. It's a good recommendation. Yeah, I really like it. It's not super expensive. And it does a good job of sketching the ideas that you have in your head. Yeah, for sure. Couple of livestream comments, just sort of get a quick shout out to Alexander says interesting. Sounds like react and Python when we're talking about the event bubbling? Yeah, very cool. And then David has equated you to Brian Aachen. Mike is to Python GUIs as Brian Aachen is to PyTest. Yeah. So really cool. I guess one more general concept. Let's talk about a little bit before we maybe just touch on some of the lessons and whatnot from the various apps and the types of things that people could go play around with them. I'm guessing the source code for these apps is on GitHub available. Even if people don't have the book, they could probably go dig it up. Yes, it is. Yeah, same same for all my stuff. And the extra thing that I would really want to talk about his layout. So layouts. Interesting, right? You, you've got these different? What are they called? resizeors? or sizers? Yes, yeah. So if you're going to put like two buttons next to each other, then you just want them to take up 80% of the space combined have a little bit of margin or something. If you just put them in a location, well, that might be true for their size, at first. But if you move the window, obviously, not so much. Right? There, they're not going to move, they're not going to change size, to talk about the different layout sizers, and how you can combine them. So how do you build like real composed UI worlds with this, you know, you could use absolute positioning, I don't recommend it. But if you made your frame unresizable, then you could totally do that. Yeah. But if you want to use sizers, I usually use box sizers. They support vertical or horizontal alignment. So if you said, you know, for vertical, everything is the default, it will add their widgets from left to right across our main horizontal by getting myself all confused. Alright, vertical is top to bottom horizontal is left to right there, as you add them, the widgets will stack in that direction. And the nice thing is you can nest the cisors. But if I wanted to, you know, add columns, I could put, you know, three or four vertical sizers boxes inside of a regular horizontal sizer, or vice versa, to just create these kinds of stacks of widgets on my UI. So let's think about this. So imagine I want to build like a photo viewer thing. And I want on the left, I want a vertical list of all of the image names, I mean, just the short image names, then, maybe folders and I click the folder and then in the right, I get like a grid of photos. So overall, I've got the panel. And then I would put a vertical sizer that has the two pieces, right? Yes, probably the one in the left would be another vertical sizer that just takes a bunch of like little image name display and things. And on the right maybe a horizontal one, or does it have to wrap with that wrap around? Or would it just shoot off the screen to the right eventually, or make them really small or something like that. It should make them smaller if you if you make it to be small, but you can also set size hence index Python that says you're not reduce this window beyond you know, like 400 by 400 pixels or Okay, like a scroll bar or something like that. Yeah, you can tell that that actually a different widget, there's a scrollable panel that you could add, and then in the scroll bar, a scroll bar will appear when you resize as appropriate, right. Okay, another way you could do that as use a splitter window, and then have your widgets, some widgets on the right and some on the left. Okay, do you really have to probably think about how do you compose these things, though? There's not like one superduper layout that's just going to do all this stuff. You're like, oh, here's a section. There's a section right? Yeah, I mean that there is a flex grid sizer and a grid sizer. So if you know your layouts gonna be kind of in a grid shape. You could use one of those grid cisors and lay them out that way. They're a little bit confusing to work with at first because you're trying to figure out you know, what does everything go? they work great for like a calculator because that's a grid. Right? Okay. And they probably not changing it's a fixed number of
20:54 like nine or whatever, yeah, these are going in there. And you could nest, you know, box sizes inside of the grids to make, give yourself more flexibility. Make the Return button bigger or something like that, as it stretches, I believe you can make each cell in a grid size or stretch differently. But you don't actually need this to do the nesting. I was thinking more like if you needed to, like have stacks of widgets in a cell within the grid site sizer, and you might need to put in different sizes inside of it. Yeah. Okay. Very neat. quick feedback for the live stream. Matt. Robin says in my last company, we used a bunch of wxPython, you book with an awesome resource? super cool. Oh, cool. Awesome. Yeah, very good. All right. Now, let's go on and talk about some of the apps in your book because I think you're thinking about like, what are the kinds of apps I could build with this framework reasonably, and stuff that fits in a book usually has to fit that reasonable categories? Like, well, we're gonna build Microsoft Word, and off, like, you know, something that does a zillion things. So let's see, the first one that you had, there was really the first meaningful one was like an image viewer, which is a little bit like, like a simpler version of what I'd sort of just described, right? Yes, I chose the image viewer, because I didn't want to take a lot of code to create something that just shows you an image on screen. And because debugs, Python uses pillow underneath, it can support most image types natively, which is really handy. Yeah, it supports, you know, the list of like, seven or eight different formats in jpg, GIF, and on and on, right, which is something that TKinter doesn't do. It only supports like two or three natively, then you have to import . It gives us a BMP, and you're like, how do I get a BMP? Like an a TIFF?
20:54 Yeah, it gets very unhappy if you do that. Yeah, that's cool. And then it started out as just you've got a button that says, choose a file, and then you show it on one of these, these image widget, which is pretty straightforward. But you know, I was still impressed that when you click the button, it's like a really clear way to open a dialog. That is the native dialog. So in your case, use your Mac file dialog, and it has like all the stuff you'd expect on the left, it's got like your favorites and your tags, and, you know, whatever customizations you've done here, binder, whatever. Yeah. Because database Python does their native. Exactly. And it is always drove me crazy that like, Oh, I know, on the real OS, I can navigate to another folder this way. But no, I'm just hitting the up arrow over and over again. And you know, it's just things you know, they just, it's nice to have it native. Yes, I agree. I've, I feel your pain.
20:54 Yeah, so to like, for example, open up file dialog, you create a context manager. And you just say with, I remember the exact command, but you give it the basically the file description, and then the file filter, and you say opening just checked to see if they hit OK versus cancel. And then you work with it in the within the context, all the wx Python dialogues, and I think maybe even the frames support using them as a context manager to open and show them. Yeah, it would make sense if you wanted to create the equivalent of a modal dialog, but a custom one that you create put that in a width blocks here, right? Would that work? If you inherit from wx dialog. I believe that well, yes. Okay. Yeah, super neat. So I guess you probably have to learn your class hierarchy. It sounds like I don't know, I this one derives from frame that one derives from dialogue.
20:54 Yeah, there's a bit of a learning curve. Yes. But once you've got the top level widgets figured out, which are frame dialog and window, and you almost never use window, you know, you're not too bad. Yeah. All right. Another one that you built was the database viewer, based on SQLalchemy, object list view, and so on. And tell us about that. I actually wrote this example A long time ago for my blog, and then I updated it for my book. I've always liked SQL alchemy. And I realized that I could create a SQL alchemy model class, and use it with Apex Python because they have a third party widget called the object ListView that basically matches a model in SQL alchemy almost exactly. I can kind of combine the two classes and make them work together in a way. So that's kind of what I did. I just made it so they could open up a SQLite database. In the book, you basically see the tie the tables, and then click on them and get the record or something like that. Yes, you can see the records. I think I made it so I can edit edit their records to or maybe that was just on my blog today. Yeah. What would you do is that shows basically the Excel looking view, that's object list view that makes wxPython has its own native widget called w x list control. And object list view is kind of a wrapper of that, that widget that makes it a lot easier to work with, in my opinion. Yeah. What about animations? I know that doesn't have anything to do with the app that we're talking about. But is there some sort of support for changing the screen or if I'm going to put something on the screen? Like I want to build a dashboard that is maybe looking at all the analytics on our system, and it updates once a second? How easy is that to do? Oh, if you're talking like a graph, a graph or even if it just has numbers like here's the current flow rate of such and such or the number of years
20:54 users on the site versus like the minutes of video watch today, up to date by the second them like that. Yeah, you have a couple options here based widgets has a, I believe it's called a device context wx.dc. There's a couple different variants of that. You can use it to basically draw whatever you want. And that's the basis for creating a lot of the custom widgets that you'll see in the wx Python demo. So you could use that to like draw any custom widgets you want. I see you just given like a rectangle or whatever, and just go crazy with the draw commands on it. Yes. All the alternative is that wx Python supports matplotlib and can embed it easily. And it also has its own pipeline library. So we can draw them without matplotlib in itself. So both of those are also options. Yeah, very nice. What's the external, like, super custom control world look like? We've got the Wix widgets. But are there like other third party libraries that you get like, oh, here's like a really fancy editable grid type of thing, or autocomplete and drop downs? Or, you know, is there an ecosystem around those types of things. And I remember in Visual Basic, and like Windows forums, there was like whole companies based around building those little extensions. Well, I know that I know, the object list view was a third party one for a while, and it still is third party. But I think the actual c++ version of it has outstripped the recurrent wrapper for it. So it's, the current wrapper doesn't follow it very well anymore. Besides that, they used to be a guy, Andrea Guevara, I believe is his name. He created a ton of awesome custom widgets for wxPython. And eventually they got wrapped into the Python framework itself. So now it's like, import
20:54 and you have access to all of those custom widgets within the Vex Python. Okay. But besides those, there's not a lot out there that I can think of that are like, just custom ones you'd add on, right? I was doing some quick searching for whether or not there's like an awesome list. Basically, for those things. I couldn't find what maybe people, someone out there knows when they can send it to us, and I'll put it in the show notes. Oh, yeah. Cool. So another one that you built was one that would look at basically zip files or tarball. And pull those apart? Yeah. What are some of the cool takeaways from that? Oh, for me, it was fun to to dig into pythons native Tarin libraries, which I haven't played with that much. And I was originally going to include the zip file. But zip files tended to be more buggy. When I was playing with it by just stuck with tar balls, keep it simple. But the main takeaway is that it works really well with wx Python, I try to show newer concepts like path lib in this book, using in conjunction with tarball. The tar file, library path pub is nice. Yeah, it's not entirely obvious when you first get to it that the division operator been taken over. No, it's not to combine elements. But at the same time, it is quite neat once you learn it. Yeah, the syntax always throws me when I see those examples on like, What? Oh, yeah. Right. That's how it works. Yeah, well, same thing for date. Time and time. deltas. Nice. Yes. And then you mix those with have strings, and you did a whole other world. Yeah, absolutely. Absolutely. All right. Another one that you discuss was he did an application for NASA's API. I don't know what NASA's API is. But that sounds fun. Tell us about that.
20:54 So this one was actually recommended to me by the Kickstarter people that were back to the book, they were like, so when I whenever I do a Kickstarter, I asked, backers, what ideas do you guys have? What do you think would be a good, good addition, and someone was like, well, NASA's API is open, basically, open source, you can query it if you have a license API key. And you can make it show you basically any pictures that NASA has publicly available. So the NASA API will let you you know, get photos of the moon, get photos of their launches, get photos of Mars, you know, whatever. And they really wanted an example of how do you make depicts Python hook up to a web API. But that's kind of what this what this chapter is about? Yeah, that's a pretty cool example. Right? A lot of fun stuff that you can check out there. Yeah, yeah. It was fun doing api.nasa.gov. You can go over there. And, you know, there's a bunch of stuff. Path maps for the moons do line element data for Earth orbiting elements orbiting the Earth? Yes. Yeah. If you update it in real time, so yeah, nice. So what did you end up actually building? Like, there's a bunch of API's there. I think that's one only like loads. It has a basically a list control widget, which I use to display the search results when you query the national search. And then when you click on them, it will load the image. So you know, if I looked up like challenger spaceflight, or Apollo, or whatever, it'll show all the public NASA images in that list box and you can click on them, and it will load the picture for you so you can view the picture. Yeah, there's a ton of room for improvement, like how to download the picture, which I believe I covered how to download it with that.
20:54 GUI. But you could also, you know, add tag editors, it could be the be the metadata in the images, right? And then you can browse it by show me all the pictures of the shuttle, or, you know, things from this mission or something like that, or from this date. Yeah. That seems like a really fun thing to play with, and just people who are looking to have a fun API out there in the world to choose. That seems like anyone. Yeah, it was. It was really neat. Yeah. Super cool. So I guess, you know, there's a bunch of other stuff that we could talk about that you wrote about. But I think one maybe final thing, one of the challenges that's not immediately obvious with Python is, how do I take my Python code and give it to somebody so they can put it in their dock or their Taskbar as a picture and click it and see it without them? without discussing, here's how you create a virtual environment. Here's how you have the right version of Python. Here's how you pip install the requirements like how do you distribute this as like what your normal people would perceive as an application? Well, fortunately, the major Python GUI builder, executable builders, support wxPython. So in the book, I use Py installer as an example, because it can package up wx Python pretty pretty easily. Okay, you have to give it a special command, like command line arguments to tell it that it's a windowed application versus a terminal application, right. I think maybe the default is to also have a terminal window, it would distribute it, but you have an odd terminal window just to the side of your app. Yeah. So if you have like any debug in your application that would show up in the terminal window, which, you know, might not be ideal. Yeah. Now, for sure. So I cover that in the book, The nice thing about PyInstaller, that also works for creating executables on Mac, for and windows, not all of them do that. I have used Py2exe pretty extensively over the years, and it works great for Windows. But you know, again, it's not gonna work for anything else. Right. So you found pyinstaller was pretty reliable across the platforms. Yeah, it works really well. The only problem I have is that I think if you do the all in one file, Windows Defender, well, well market as malicious and delete it. Oh, that's not good. And I think it does that for you know, whether it's a winner debates Python file or not, it anytime you create the one the one file executable with PI installer, it's like, oh, that's a bad file. I'm gonna delete it for you not ideal? No, I think you can, someone must have used, used it to try to package up a virus or something at one point, and then it got fingerprinted. And that was that. Yeah, I think you can self sign the file or something to get around that. But I don't go into that. And I think you got to register as a developer with Microsoft to get like a signing certificate or something. I don't think I've ever done that. So but there are like when you say try to run it. And same thing on Mac, it could either sometimes it'll completely block it. Sometimes it'll say that came from the internet, but we kind of recognize that person, or I guess if you superduper sign it, it'll just run. Yes. Yeah. opinion on on the platform. So another thing, you know, one thing that I did is I created this little little app that runs in the Mac menu bar, and I created that with Py2app. And then it just gives people a .app file zipped up. But then you unzip it. It's a .app file. Yeah. And then you can just run it. And that's worked well, but like Py2exe Py2app is a Mac only thing, right? Like one platform. I know. py2 app also works with wx Python. My experience, yeah, these sort of packaging utilities. They work pretty well for the different platforms, if you're using wx Python. Yep. I haven't had any problems with them. You can get squirrely things with other packages, but not usually with wx. Yeah, very cool. All right, Mike. Well, I think about is all the time we have t talk about GUI and stuff, at least the wx Python, but give us your verdict. Is it something you enjoy working with or building apps that people are liking with it? I don't know about other people, but I still use it whenever I can. for work, I'll create, you know, simple apps to demo, whatever I need to demo to my employer or my my pm. So I mean, you can still throw together a really simple app with wx Python and only 100 lines or you know, a couple 100 lines. And they'll show off something that looks awesome across platforms. avoca. Yes, again, I know I keep going on and on. But the native bits just make me happy.
20:54 A quick couple of questions from the live stream. One is it doesn't want to show up. They go. If I purchased the book, wx makes Python recipes. Is it still relevant or outdated enough? My this book is yours. I have a wx Python cookbook from a press. I believe the examples and it's still work, but they're kind of like all over the place. I tried to group them intelligently but I mean, they're helpful, but they're not going to like help you. I don't know how to describe it. But they're they're more like, these are very specific things. So read the Table of Contents before you buy that one. If he's talking about Cody pre cords book, which is depicts Python recipes from packt Publishing. I haven't read it in a while so I don't remember. Yeah, and I have no experience with it either. So but check out this one. This one's got at least and good little apps in it. For sure. Yeah. Okay. So I guess with that
20:54 I'll ask you the final two questions that I always asked everyone, if you're going to write some Python code what editor are using these days? I'm still a big fan of wing ide it. so I hear a lot of people on the VS code wagon these days like why wing for me, I still like that. It has a source code source assistant, which basically shows you the doc strings and links to the documentation live at all times for whatever your whatever line of code you're on, though, you know, if you have imported something, I'll show you all that stuff and basically help you learn new modules as you work. The other thing I really like is the debugger. The debugger on it is really good. Yeah, fantastic. Okay. And then notable PyPI package. I mean, there's always w x Python, if you want to throw that one out there. But you got another one in mind. For me, I'd probably be open open pi Excel, because I've been working with it a lot. last couple years. Open Py, Excel basically lets you read and write Excel files, the newer format, right, the XLS. X version? Yes, it does. And you can do formulas and formatting and everything. Is that right in my
20:54 formulas are kind of iffy. But the rest of it is it does do nice, pretty cool. So so many people, I'm sure receive Excel files all the time. And they want to like, process it with code rather than with, you know, a mouse and keyboard. So yes, awesome. Awesome. All right, well, final call to action. People want to get started with w x Python, what do they do or they can check out my book, or you can just go to wxpython.org and get everything you need right there. Awesome. Yeah, I'll put a link to that in the show notes. So thanks, everyone, for listening. And, Mike, thanks for all you're doing around the GUI stuff. Oh, thank you so much for having me. You bet. Bye. Bye. This has been another episode of talk Python to me. Our guests in this episode was Mike Driscoll and it's been brought to you by Linode & Us over at talk Python training and the transcripts are brought to you by Assembly AI. Simplify your infrastructure and cut your cost bills in half with Linode. Linux virtual machines develop, deploy and scale your modern applications faster and easier. Visit 'talkpython.fm/linode' and click the Create free account button to get started. Transcripts for this and all of our episodes are brought to you by Assembly AI. Do you need a great automatic speech to text API get human level accuracy in just a few lines of code visit 'talkpython.fm/ assemblyAI'. To level up your Python. We have one of the largest catalogs of Python video courses over at talk Python are content ranges from true beginners to deeply advanced topics like memory and async. And best of all, there's not a subscription in sight. Check it out for yourself at training .talkpython.fm. Be sure to subscribe to the show, open your favorite podcast app and search for Python. We should be right at the top. You can also find the iTunes feed at /iTunes, the Google Play feed at /play and the direct RSS feed at /RSS on 'talkpython.fm'. We're live streaming most of our recordings these days. If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube. This is your host Michael Kennedy. Thanks so much for listening. I really appreciate it. Now get out there and write some Python code.