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 building and distributed Python window-based applications.
This is Talk Python to Me, episode 326, recorded July 14th, 2021.
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 at Talk Python. 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 all offering during our segments. It really helps support the show.
Do you want to learn Python, but you can't bear to subscribe to yet another service?
At Talk Python Training, we hate subscriptions too. That's why 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.
So stop subscribing and start learning at talkpython.fm/everything.
Mike, welcome to Talk Python to Me.
Yeah, thanks so much for having me again.
Yeah, it's great to have you here. Maybe we can just remind people of the last time you are here.
You wrote a really cool book called, I think it was Python Interviews. Do I have the title correct?
Yes, that's correct.
Yeah, and that was back in episode 156, way back in 2018, three years ago, I guess, more than that.
But it was a history book, so I 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 were sort of competing 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. Although there's some good stuff in the Brett Cannon interview as
well.
Yeah, there's great stuff all over. I'm just trying to think of the one that I can remember years later,
you know?
Yeah.
Yeah. So it's been a couple years since you've been on the show. What have 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 WX Python and Report Lab. I redid Python 101,
which was my first book.
Report Lab is about like working with PDFs, right?
Yes. You can use it to create PDFs. But that book also covers how to edit, or I shouldn't say edit,
how to read and get data out of an existing PDF as well.
Yeah. Cool. You got a couple of 101, 201 type of books as well.
Yes.
Like learning Python.
Yep. Python 101 is for beginners and 201 is kind of intermediate advanced.
So if I was like a sophomore, I 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 are you up to?
Oh, I still 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
these books and I occasionally contribute to RealPython as well.
A lot of good stuff going over RealPython. Dan and crew keeps that content flowing over there for sure.
Yep.
Yeah, absolutely. So we're going to talk about building GUIs or GUIs as some people say them. I don't know.
Are you a GUI or are you a GUI sort of person?
I usually call it GUI.
Yeah, me too. So we're going to talk about those for Python, which I think is interesting because there are,
there 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 picking another framework that's a nice
cross-platform framework and like making it friendly for Python, right? I'm thinking of like PyQt or even WXPython, right?
Yeah, it's usually a C++ wrapper that preexisted 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 APIs, right? Like Win32 or what is it? Coco on macOS, 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 something else. Like BeWares Toga,
I don't believe is wrapping the native, I was trying to look, I guess it is wrapping in a way,
but it's not wrapping a preexisting framework.
Right, right. It's probably super low level. Like here is a, literally create a window that is a button
and that's it. Like not like Qt or something. Yeah, I think Toga is actually like, you know,
trying to render the Coco widgets or the Win32 widgets itself, you know, rather than calling like
Qt 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, TK Enter, which is really the Python interface to TCL,
TK, right?
Mm-hmm. 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 QIs with Python, right? I mean, in the sense that it ships with it.
It ships with it. However, on like Linux, the system Python does not come with it.
Okay. So you still got it.
And I believe, I believe Mac is the same way. You have to install it separately for its system Python
too.
Yeah. That wouldn't surprise me. Well, you know, the system Python and Mac is all sorts of outdated and
whatnot, basically, right? Like 2.7, who knows what, right? But-
Yeah. But it always surprises me when I go to import TK Enter and it's like, oh, it's not there.
Like, what the?
Yeah, exactly. Tell us about this one. Like, what's the good side? When would you use it? Or
would you use it? When wouldn't you use it?
I don't like it because it looks a little old-fashioned, but mainly because it draws all its
own ridges, just like some of the other GUI toolkits. So basically, when you create a TK Enter GUI,
you know it's a TK Enter GUI 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 it work. So, you know, as a learning way to create a GUI, it might be a good first,
you know, a good beginner or first GUI to create with.
Yeah, absolutely. Here, I put up on the screenshot, the screen for us to see there's like this TK Enter 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 any 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, it's like a predate
jupiter or something like host map plotlib exploration and stuff. And that looks like a
pretty solid app to me.
Yeah. TK Enter did add a submodule called TTK, which does look a lot more native across platforms.
You can make it look nice, actually, 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 interface. And one other thing I do
want to note about TK Enter is it's themable. So if you want it to look, you want to add themes to
your GUI, you want to take it as an option for that.
Oh, interesting. It was like, so for example, you could give it a macOS like theme that turns
on on that platform and a Linux theme, maybe dark mode and a not dark mode.
Yeah. I was thinking of dark modes, light modes, be giving them a certain color things,
kind of like a Winamp type skin.
Yeah. Oh man. Remember how crazy those skins would get? They'd get like 3D with little holes
cut in them. And yeah, that stuff got, that got a lot of little drawers, like an alien tongue
would shoot out. And that's where like the playlist would be. Don't do that people.
Yeah. Don't do that.
Okay. So for the most part, TK Enter is built in ish. At 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 of cross-platform stuff is Qt, Qt and PyQt.
There's been a lot of different versions of PyQt. There's been a lot of stuff with licensing.
So like right here on the homepage, it says licensing. PyQt is dual license on all the
platforms under DPL3 and the Riverbank commercial one. Unlike Qt, PyQt is not available under LGPL,
which is, I guess what you would need for like a commercial closed source app. And then 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, whoa, why is it so complicated?
Yeah. PyQt is kind of confusing when it comes to its licensing structure.
Yeah. Which is 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 Robo3T. And if you look at Robo3T, 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 PyQt, you could use Qt for Python,
which is the new name for PySide.
That's right.
And it has a bit more permissive licensing structure.
That's 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 still PySide? How interesting.
It's like PySide 6, I think. Yes.
Yeah. How interesting. So this, I think Qt's 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 RoboMongo just because
it seemed like a good app and like, oh, this is a Qt app. It's not a Python. It's 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 have 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 ton. And while it draws
all of its own widgets itself, it's not actually using the native widgets. It looks native.
At least they made an effort. Yeah. Yeah. Again, this one is also a themable. If you want to do themes,
you can change, you know, dark mode, light mode easily because that's all drawn itself.
I think PyQt and PyQt for Python both support QML, which is kind of an XML version of the C++ library.
So you can kind of write it, write your GUIs in a markup language.
Yeah, that's right. It's a little bit like XML or XAML from the Microsoft space. Yeah, that's right.
It also has a, what you see is what you get editor. I think it's Qt Designer.
It 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++ cute 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 of the frameworks, right? Not just these Python
ones we're highlighting, but you know, Xcode, whatever, right?
I think that's just a 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. Kivy, I heard about a lot from sort of
building mobile apps with Python in interesting ways. It's kind of got this game, draw your own UI
sort of feel to it.
Yeah. It's also cross-platform. It runs on mobile too, though. So you can deploy its apps to Android and
Apple OS. 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 Kivy itself. So they look like a Kivy 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 Marseille map exploration type thing, right?
They have a Kivy garden, I believe, that also showcases lots of custom widgets.
Yeah. So when I look at the... I'm scrolling through the gallery here, I feel like there's a lot of 2D
sort of interactive things, a lot of games or stuff like that, right? So it's... If I wanted to build an
app that maybe looked like it used the Windows rich text box and the Windows button, so it looked like
a, I don't know, a 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.
Okay.
And I believe Kivy is based on, or written on top of Pygame. So it has... That's why I can do games so well.
Right. That sounds familiar to me as well. And apparently the winner of the Python Discord
Code Jam 6 was done in Kivy. So that's pretty cool.
That is cool.
As well as second place.
So I was unaware.
Is there a third place one down here?
Yeah, it is.
Wow.
They have a clean sweep of the podium with Kivy. 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 its own opinions for how it works is
PySimple GUI. I think Mike Barnett, if I'm remembering correctly, is working on that.
Yeah.
And yeah, the idea is to make it super simple to just get a basic UI up and running, right?
Yeah.
So PySimple GUI wraps, I think, four or five other frameworks. So it wraps tkenter, WX Python,
PyCute, Remy, which is a mobile thing, and something else. And basically it 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
import PySimple GUI to import PySimple GUI Qt or PySimple GUI WX, you can get that native look and feel
because you're using WX acute.
Oh, that's a really cool aspect, right? That you can swap out the widget engine or something,
basically.
Mm-hmm. Yeah. The default is tkenter.
Yeah. Probably because it's the least dependencies and you don't have to 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
has one or two buttons and an input and a progress bar, maybe this is a good option.
They can do quite a bit of complex GUIs too. There's a demo package that they have that
shows how to integrate it with matplotlib and opencv and lots of other things. These examples
don't show the advanced stuff it can do.
Right. I'm just sort of paging through the gallery, the screenshot they have on the site
there, which we'll link to.
And again, since it's using tkenter, it also does themes natively.
Yeah, it can just float.
At least for the tkenter part.
Yeah, exactly.
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 their award-winning support, which is offered 24-7, 365 to every level of user, to 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's one-click app marketplace, or build it all from scratch and manage everything yourself with supported centralized tools like Terraform.
Linode offers the best price-to-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.
That's talkpython.fm/Linode, or just click the link in your podcast player's show notes.
And thank them for supporting Talk Python.
One that you put in the list that I haven't really done anything with is DearPyGUI, a fast and powerful graphical user interface toolkit for Python with minimal dependencies.
Tell us 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 scientific visualization and exploration.
Yeah, I think it is.
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 yet, because I didn't pull up in our little list here, but it's a toga from Beware.
You touched on that, right?
Yeah.
So all this stuff over at Beware is 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, ah, 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 widgets aspects, but it's also listed in sort of the maturity level as early development, right?
So I'm not sure if this is pretty 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.
It's somewhat understandable, but I think they recently added Android support.
So I think that they're focusing more on the mobile stuff than, you know, like Windows and Macs, native OSs.
Yeah.
The last commit was a merged PR from Russell Keith McGee four days ago.
So there's still, still action.
Yeah.
They're still working on it.
All right.
Well, that brings us over to the WX Python, 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?
Sure.
Yep.
So give us the quick overview of WX Python sort of compared to these other options we've been covering.
So WX Python is again, a C++ project.
It 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 DAPX Python is that it does do native widgets wherever possible on all platforms.
Yeah, that's cool.
So 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 feature is not supported, but you want it.
Well, like, all right, here's that something that'll do for now.
Yeah.
Very cool.
You know, it looks to me like it checks a lot of the right boxes.
What's the licensing story?
It's very permissive.
Yeah.
I'll pull up there.
I'll pull up the repo and hit their license doc and see what I can find.
I know they called it the WX Python license, but I'm trying to remember.
Ah, that's right.
It looks LGPL-ish.
Yeah.
I think it is mostly LGPL.
Mm-hmm.
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's 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.
Yeah.
The Phoenix release and then the legacy or traditional version.
What's the story of that?
So, you know, Python 3 came out and a lot of people, you know, fussed about supporting it.
It was a pretty big deal to port WX Python to Python 3 because WX Python has a really small
group of core developers.
But eventually he created, or 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 Wix 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 Wix Python.
And that also made it pip installable.
So that was super awesome when he got that working.
So if I want to use it, I can just pip install DevX Python or Wix Python.
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 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, a lot of times there's elements there you got to add.
It doesn't seem outrageous.
No.
Yeah.
So another thing that I'm a big fan of to the extent that they work, and the better that
it works, the more I'm a fan of it, is the GUI designer.
So there's two over here, right?
We've got like this Wix form builder in the Wix Glade.
I think I tried the Wix form builder and it just, it kept crashing.
Not like it would start and was unstable.
It would not start for me.
And I don't know what the deal, maybe it was the version of macOS I was running on or something.
But what's the story?
Are these things that people would use?
Yeah.
What's the story around the WYSIWYG side of these?
WX Python traditionally hasn't had really a WYSIWYG editor, but people have tried to build
them.
So I think Wix Glade is probably the one that's been around the longest.
Okay.
And probably the best supported.
I don't think it, I think it supports the core widgets of WX Python.
If you were to pull up the WX Python demo app, there are like a hundred, I would say at least
a hundred widgets, maybe more, maybe 200.
So the core widgets, you know, like buttons.
Do I find that under widgets?
You would find that under, let me see, downloads.
Downloads.
There you go.
Unfortunately, it's actually something you run.
Yeah, sure, sure.
So if you can download, I think I have run that before and you basically, it's like got all
these windows that'll show you little use cases for this widget or that widget, right?
Yeah.
It also shows you the code and you can edit the code live in the demo and see how it, how
it changes the widgets.
Oh, that's neat.
It does a decent enough job.
I think it outputs a Python file.
So that's nice.
I mean, it doesn't put, you know, like Qt's designer output's a UI file that you have to
figure out how to import and then use.
This one actually outputs a Python file.
Oh, that's nice.
Yeah, that's really good.
So I'm looking at the screen here and it looks like Audacity, the well-known audio editing
app is built in DubX.
I'm guessing.
Otherwise, there's no reason they would feature it.
I believe that's true.
I'm not sure if it's Wix widgets itself.
Yeah, it's on the Wix widgets site.
So I'm pretty sure it's a C sort of thing.
But yeah, these are pretty good looking apps that you can like sort of page through all their
screenshots on just Wix widgets.org.
Almost even like an auto trader looking thing and like a diff tool.
Yeah, file merge.
Yeah, Audacity.
Yeah, I believe one of the Linux diff tools is written with WX Python.
And I had heard that the Dropbox UI was written with WX for a while.
I don't know if it still is or not.
Cool.
So it seems like there's quite a rich library for working with these things with WX Python
or Wix Python.
And I guess maybe one of the nice ways to explore this would be, where am I going to
go?
I'm going to 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 recent, but somewhat recent.
Creating GUI applications with Wix Python, which is pretty cool.
And a comment from the live stream out there.
Juergen says, congrats on the successful fundraiser for your latest book, which is not this book,
but like...
No.
What book is that that you're just working on now?
I'm working on one that talks about automating Excel with Python using OpenPy Excel.
Well, that's certainly a hot topic indeed.
What's the story with this creating GUI apps with Wix Python in your book?
Feels like from the extent that I got to read it, which is not all of it, but some of it.
It does a quick introduction of how to work with the widgets and stuff and get some stuff
on the screen, understand the layout a little bit.
And then it goes through and just builds like a bunch of different apps, like a nice little
image viewer, a database viewer tool that uses SQLAlchemy to like explore stuff there,
a calculator, an archiver, MP3 tag editor, those types of things.
You want to maybe just tell us like kind of some of the key elements before we actually,
before we get into those, let's just maybe, it's hard in code, but on audio to talk about
code, but maybe just give us like a sense of what is it like to get a window and a button
on the screen or something like that?
Sure.
So, you know, Linux Python, much like PyQt, they're all class-based.
So, you're going to be inheriting from different classes to create all the widgets online.
Whereas with Tcancher, you don't have to do that.
I see.
So, you might make like a window class and like a layout main section class or something like
that?
Kind of.
Okay.
Layouts usually aren't needed to be subclassed, but like you subclass a frame, which is the main
window.
You can subclass a panel, which is kind of like the tabs on your Firefox or Chromebook.
You can create a notebook object that has multiple panels when each of those panels is a tab,
basically.
I see.
So, it has like a multi-doc version or style that it'll support.
Correct.
Yeah.
Okay.
Cool.
And within your frame, you have your panel.
And then within the panel, you have your widgets.
And so, those are your children widgets.
Like you have your buttons or your, you know, your scroll bar or your check boxes or whatever.
The code can get kind of unruly, but for just creating something really simple, you can do
it in less than a hundred lines of code most of the time.
But, you know, once you start doing like anything complex with WX Python, you're going to start
adding a lot of code.
Right.
Because if you're going to have, say, three buttons and a text field and you want to,
you want to figure out how they lay out, there's like a couple of things that you're going to put
just on the layout side.
And then you're going to have to hook potentially the events.
You can abstract that away a little bit.
So, it's not too bad.
Like if all the buttons do something similar, then you can make that really short.
But yeah, if you, if all the buttons do something completely different, then you could, you know,
you have three different functions.
The way I have written wrappers to make laying that stuff out simpler.
So, I don't have to repeat the same boilerplate.
Yeah.
All the time.
Yeah.
As soon as you're like, why is this so complicated?
Why do I keep doing this?
Maybe that's the time to think about how do I do it just one more time with a little more
polish and then never again.
Yeah.
So, the widgets have events, right?
Like on a Windows, it'd be like a WM key down, like win32 event that is then translated to
the Wix event, which then calls back into, say, Python, right?
And what you do is you give it just either a class level or just a regular function.
Whenever somebody clicks this button, call this function, right?
Yes.
It's usually like for buttons, it's like WX.event button, and then you just bind it to a function.
Right.
Or you could bind it to the entire app if you wanted to, so it captures the clicks.
Yeah.
What I thought was interesting looking through the framework was in many UI framework, like
native compiled built-in frameworks, they don't, basically the button gets a click or it doesn't,
or somebody clicks the thing outside of it or it doesn't.
But in JavaScript, we have like bubbling events that go up and down.
So, if I click on a label, but the label doesn't handle it, like, but somewhere higher up, maybe it's in a div and the div is handling the event, like that would catch it, right?
So, you have this ability to say, go up until it's the right level to deal with this action.
And it looks like WX Python has that as well.
Yes, it does.
Yeah.
That was a little surprising that you can sort of bind the same event at different levels and then either capture it or let it keep flowing up.
So, they both get hit, I guess.
Yeah.
You can do that and you can, you know, execute your event and then you can say, I think it's event.skip.
Yeah.
And it'll go to the next level.
Right.
That's like, don't let me consume the event.
Let it keep going.
Mm-hmm.
Bubble it up or something.
Yeah.
Really nice.
So, one thing that you talked about that I thought was interesting before we get into maybe a little more detail is you talked about, it's really nice to have a conception of what your app is going to look like, especially around layout, right?
Mm-hmm.
Yes.
So, you recommended, well, one is just like writing stuff out on paper, which is always good.
We also recommended using Balsamic as something where you could potentially sketch out the UI.
Yeah.
I really like Balsamic because it just makes, it makes laying stuff out kind of a breeze.
You could also, you know, you could use that cute designer because it's free and open source.
You could use that to lay, to draw a layout too.
Right.
Even though your destination is not ultimately cute.
Correct.
But it still lets you drag the widgets around, right?
Yeah.
So, you could still get a good idea of what you want it to look like using that.
Yeah.
I guess if you had a really old version of Visual Basic laying around.
Yes.
That also works.
I thought about that.
The VV6.
I mean, that thing went out of support like in the 90s, but you might get it to run.
But yeah, the Balsamic one.
I really like this.
I've used this for prototyping a couple of things.
I think I used it a lot when I was building the Tuck Python training platform and stuff like that.
But it's one of these wireframe type of tools that like specifically is not meant to look native or finished.
Right.
It kind of looks as if you had drawn it by hand.
Like the web browser, it's sort of wiggly lines as if you had sketched that out.
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.
A couple of live stream comments.
Just to get a quick shout out to you.
Alexander says, interesting.
Sounds like React in Python when we're talking about the event bubbling.
Yeah.
Very cool.
And then David has equated you to Brian Okken.
Mike is to Python GUIs as Brian Okken 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.
And 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 really want to talk about is layout.
So layout's interesting, right?
You've got these different, what are they called?
Resizers?
Resizers, 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 and 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.
All right.
Yeah.
They'll just stay there.
They're not going to move.
They're not going to change size.
Talk about the different layout sizers and how you can combine them.
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 set it for vertical, which I think is the default, it will add the widgets from left to right across, I mean, horizontal.
I get myself all confused.
All right.
Vertical is top to bottom.
Horizontal is left to right.
So as you add them, the widgets will stack in that direction.
And the nice thing is you can nest the sizers.
So if I wanted to, you know, add columns, I could put, you know, three or four vertical sizers, box sizers inside of a regular horizontal sizer or vice versa to just create these kind of stacks of widgets on my UI.
All right.
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, you know, 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 on 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?
Would 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 make it too small.
But you can also set size hints in Dabix Python that says, do not reduce this window beyond, you know, like 400 by 400 pixels or whatever it is.
Okay, just get like a scroll bar or something like that.
Yeah, you can tell.
So that's actually a different widget.
There's a scrollable panel that you could add.
And then the scroll bar will appear when you resize as appropriate.
Right.
Okay.
Another way you could do that is use a splitter window and then have your widgets, some widgets on the right and some on the left.
Interesting.
Okay.
So you really have to probably think about how do you compose these things, though?
There's not like one super duper layout that's just going to do all this stuff.
You're like, here's a section.
There's a section, right?
Yeah.
I mean, there is a flex grid sizer and a grid sizer.
So if you know your layout is going to be kind of in a grid shape, you could use one of those grid sizers 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, where does everything go?
They work great for like a calculator because that's a grid.
Right.
Okay.
But.
And they're probably not changing.
It's a fixed number of nine or whatever.
Yeah.
Things are going in there.
And you could nest, you know, box sizes inside of the grids to make, give yourself more flexibility.
Mm-hmm.
Make the return button bigger or something like that as it stretches.
I believe you can make each cell in a grid sizer stretch differently.
So you don't actually need to do the nesting.
I was thinking more like if you needed to like have stacks of widgets in a cell within the grid sizer, then you might need to put a different sizer inside of it.
Yeah.
Okay.
Very neat.
Quick feedback from the live stream.
Matt Robinson says in my last company, we used a bunch of Wix Python.
Your book was 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 know, 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 category.
It's not like, well, we're going to build Microsoft Word and 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 know it wouldn't take a lot of code to create something that just shows you an image on screen.
And because JPEG's Python uses pillow underneath, it can support most image types natively, which is really handy.
Yeah.
It supports, you know, the list is like seven or eight different formats, ping, JPEG, GIF and on and on.
Right.
Which is something that TK Enter doesn't do.
It only supports like two or three natively.
And then you have to import pillow.
Yeah.
Give us a BMP and you're like, how do I get a BMP?
Like in a TIFF?
Like where did it?
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 widgets, 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 dialogue that is the native dialogue.
So in your case, you used your Mac file dialogue 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 to your binder, whatever.
Yeah.
Because JBS Python does their native.
Exactly.
And it's always drove me crazy that like, oh, I know on the real OS, I can navigate to another folder this way, but now I'm just hitting the up arrow over and over again.
And, you know, it's just those little things, you know, they just, it's nice to have it native.
Yes, I agree.
I feel your pain.
Yeah.
So to like, for example, open up file dialogue, you create a context manager and you just say with, I don't remember the exact command, but you give it basically the file description.
And then the file filter and you say open and you just check to see if they hit okay 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 dialogue, but a custom one that you create, put that in a width block too.
Right.
Would that work?
If you inherit from Dabix dialogue, I believe it well.
Yes.
Okay.
Yeah.
Super neat.
So I guess you probably have to learn your class hierarchy.
It sounds like I got to know.
I got, I, this one derives from frame.
That one derives from dialogue.
Unfortunately, there is a bit of a learning curve.
Yes.
But once you've got the, the top level widgets figured out, which are frame dialogue 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.
So I actually wrote this example a long time ago for my blog, and then I updated it for my book.
I've always liked SQLAlchemy, and I realized that I could create a SQLAlchemy model class and use it with Dabix Python because they have a third party widget called the object list view that basically matches a model in SQLAlchemy almost exactly.
So 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 that I could open up a SQLite database in the book.
Do you basically see the tables and then click on them and get the records or something like that?
Yes.
You can see the records.
I think I made it so I can edit the records too, or maybe that was just on my blog that I did that.
Yeah.
What widget do you use that shows basically the Excel looking view?
That's object list view.
Dabix Python has its own native widget called WRX list control.
And object list view is kind of a wrapper of 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?
So 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 users on the site versus like the minutes of video watch today up to date by the second.
Something like that.
Yeah.
You have a couple of options.
Dabix widgets has a, I believe it's called a device context.
Dabix.dc.
It has a couple of different variants of that.
You can use it to basically draw whatever you want.
And it's the basis for creating a lot of the custom widgets that you'll see in the Dabix Python demo.
So you could use that to like draw any custom widgets you want.
I see.
So you're just given like a rectangle or whatever and just go crazy with the draw commands on it.
Yes.
The alternative is that Dabix Python supports matplotlib and can embed it easily.
And it also has its own pyplot library.
So it can draw them without matplotlib itself.
So both of those are also options.
Yeah.
Very nice.
What's the external like super custom control world look like?
So 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 auto completing 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 current wrapper for it.
So it's the current wrapper doesn't follow it very well anymore.
Besides that, there used to be a guy, Andrea Gavanna, I believe is his name.
He created a ton of awesome custom widgets for Dabix Python.
And eventually they got wrapped into the Python framework itself.
So now it's like import WX.agw and you have access to all of those custom widgets within
Dabix Python.
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 types of things.
I couldn't find it, but maybe people, someone out there knows the one, they can send it
to us and I'll put it in the show notes.
Cool.
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 dig into Python's native Tarian 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.
So I just stuck with tarballs to keep it simple.
But the main takeaway is that it works really well with WX Python.
I try to show newer concepts like Pathlib in this book using, you know, in conjunction with
the tar file library.
Yeah.
Pathlib 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.
I'm like, what?
Oh, yeah.
All right.
That's how it works.
Yeah.
All same thing for date time and time deltas.
Nice.
Yes.
And then you mix those with f-strings and you get into a whole other world.
Yeah, absolutely.
Absolutely.
All right.
Another one that you discussed was creating an application for NASA's API.
I don't know what NASA's API is, but that sounds fun.
Tell us about that.
So this one was actually recommended to me by the Kickstarter people that were back to the
book.
They were like, so whenever I do a Kickstarter, I ask the backers, what ideas do you guys have?
What do you think will be a good addition?
And someone was like, well, NASA's API is 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 get photos of the moon, get photos of their launches, get
photos of Mars, you know, whatever.
Nice.
And they really wanted an example of how do you make Dibix Python hook up to a web API?
So that's kind of what this chapter is about.
Yeah.
That's a pretty cool example, right?
There's a lot of fun stuff that you can check out there.
Yeah.
It was fun.
So at api.nasa.gov, you can go over there and yeah, there's a bunch of stuff.
Pad maps for the moons, two-line element data for earth elements orbiting the earth.
Yes.
You update it in real time and so on.
Yeah.
Nice.
So what did you end up actually building?
Like there's a bunch of APIs there.
I think this one only like loads, it has a, basically a list control widget, which I use
to display the search results when you query the NASA search.
And then when you click on them, it will load the image.
So, you know, if I looked up like Challenger space flight 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 the GUI.
But you could also, you know, add a tag editor.
So you could view the metadata in the images.
Right.
And then you could 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.
Cool.
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 a neat one.
Yeah, 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
doc 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.
How do you distribute this as what normal people would perceive as an application?
Well, fortunately, the major Python GUI builder, executable builders support WX Python.
So in the book, I use PyInstaller as an example, because it can package up WX Python pretty easily.
Okay.
You have to give it a special command line argument 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, it'd show up in the terminal window, which,
you know, might not be ideal.
Yeah.
No, for sure.
So I cover that in the book.
The nice thing about PyInstallers, it also works for creating executables on Mac and
Windows.
Not all of them do that.
I have used Py2XE pretty extensively over the years, and it works great for Windows.
But, you know, again, it's not going to 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
will mark it as malicious and delete it.
Oh, that's not good.
And I think it does that for, you know, whether it's a WX Python file or not.
Anytime you create the one file executable with PyInstaller, it's like, oh, that's a bad
file.
I'm going to delete it for you.
Not ideal.
No.
I think you can...
Someone must have 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 didn't go into that
in the book.
Yeah.
I think you got to register as a developer with Microsoft to get like a signing certificate
or something.
Mm-hmm.
I don't think I've ever done that.
So, but there are, like when you say try to run it, you know, 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 super duper sign it, it'll just run.
Yes.
Yeah.
Depending on the platform.
So another thing, you know, one thing that I did is I created this little app that runs
in the Mac menu bar, and I created that with Py2App, and then it just gives people a .app
file, well, 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 Py2App also works with WXPython, my experience.
Yeah.
These sort of packaging utilities, they work pretty well for the different platforms.
If you're using .duvx Python.
Yes.
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 to talk about GUIs and stuff, at least .duvx
Python.
But give us your verdict.
Is there something you enjoy working with, 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 simple apps to demo whatever I need to demo to my employer or my PM.
So, I mean, you can still throw together a really simple app with WX Python and only a hundred lines,
or, you know, a couple hundred lines.
And they'll show off something that looks awesome across platforms.
Yeah, very cool.
Yeah, again, I know I keep going on and on, but the native bits just make me happy.
A quick couple of questions from the live stream.
One is, it doesn't want to show up.
There you go.
If I purchase the book, WX Python recipes, is it still relevant or outdated?
I'm not familiar with this book.
Yeah.
Is this yours?
I have a WX Python cookbook from A-Press.
I believe the examples in it 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 more like, these are very specific things.
So read the table of contents before you buy that one.
If he's talking about Cody Precord's book, which is Dibbix Python recipes from Pact 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 you can check out this one.
This has got at least 10 good little apps in it for sure.
Yeah.
Okay.
So I guess with that, I'll ask you the final two questions that I always ask everyone.
If you're going to write some Python code, what editor are you using these days?
I'm still a big fan of Wing IDE from Wingware.
Cool.
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, what do you call it, a source assistant, which
basically shows you the doc strings and links to the documentation live at all times for
whatever line of code you're on.
So, you know, if you've imported something, it'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 WX Python if you want to throw that one out there, but you got
another one in mind.
For me, it would probably be OpenPyXL because I've been working with it a lot the last couple
of months.
So OpenPyXL basically lets you read and write Excel files, the newer format, right?
The XLSX version.
Yes, it does.
And you can do formulas and formatting and everything.
Is that right?
Am I...
Formulas are kind of iffy, but the rest of it is, it does do.
Nice.
Pretty cool.
So many people, I'm sure, receive Excel files all of the time and they want to process
it with code rather than with a mouse and keyboard.
So very nice.
Awesome.
All right.
Well, final call to action.
People want to get started with WX Python.
What do they do?
They can check out my book or you can just go to WXPython.org and get everything you need
right there.
Awesome.
Yeah.
And 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.
Thank you so much for having me.
You bet.
Bye.
This has been another episode of Talk Python to Me.
Our guest on 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 cloud bills in half with Linode's 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.
Want to level up your Python?
We have one of the largest catalogs of Python video courses over at Talk Python.
Our 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.
I'll see you next time.