Tkinter vs. PyQt: Which Python GUI framework is right for you?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
greetings python coders alan e moore here beard and all if you watch this channel much you know probably that i am the author of this book gui programming with python a book that is all about pie cute what you may not know is that i'm also the author of this book python gui programming with tk enter now that book as you probably can guess is about tk enter and a lot of people will ask me because i've written one book on pie cute and one book on tk enter which one should i choose i thought for a while about doing a video on this and having code examples and live coding and pictures and all kinds of stuff but i thought you know what that's going to get bogged down and never happen so here we are on a wednesday night kids are in bed i'm chilling out i thought let's just do this old-fashioned youtube style but on the webcam let's talk it out so here we go this is pi cute versus tk enter now i just want to be clear when i'm talking about pi cute i am talking about pi q widgets not about qml that's a totally different thing i'm really comparing both of these because they're both frameworks aimed at what i would call traditional gui's or little gray box gui's stuff you'd make like a productivity application in not something that looks mobile or web like not what some people would call modern these are for more old school i need buttons and text box and you know things like that um so we're going to compare these now they're both similar in that they both come from other languages and other toolkits tk enter comes from tk or teak which comes from the tcl or tickle language the combination of which is called tickle teak if you have never heard of tickle teak and you're under 30 i would totally understand it's pretty much only around these days sorry tickle teak people but it's pretty much only around these days because it's in python now cute on the other hand pie cute wraps cute which is a massive c plus plus tool kit and framework and it's used by tons of people big companies you've heard of programs you probably run right now use cute and pi q gives us access to that if you are a programmer of any kind i really hope you've heard of c plus plus so i don't need to explain that both of them are open source both of them are cross-platform except neither one of them is really big on mobile now cute may be an exception or pie cute it's possible in theory to make a pie cute app and put it on mobile i have never succeeded in doing it if you have you are a smarter person than me and please get in touch with me i'd love to talk to you so that's the similarities let's talk about the differences first off is the license uh tickle teak is bsd licensed very liberal very free you can do whatever you want with it and of course tk enter itself the bindings for tickle teak they are part of the python standard library so if you can do it with python you can do it with tk inter you can develop commercial stuff if you want to you know no restrictions you can develop open source you can use gpl you can use whatever whatever license you want it's pretty wide open now piqued on the other hand is gpl so you're pretty much going to be writing open source software with pi cute unless you are willing to buy a commercial license from the company that makes pycute riverbank software in addition to that you need to buy a commercial license from the cute company that makes cute cute itself is lgpl which what exactly that means in terms of you writing whatever software and distributing it however you want ask your lawyer or argue about it down there in the comments i don't really know there is such a thing as pi side which are python bindings from the cute company also lgpl so a little freer in terms of licensing than pyq itself you do supposedly need a commercial license still to make commercial software but that's from the cute company so kind of one stop shop it's about 95 percent the same as pi cute so when we're talking about pi q and pi side it's it's effectively the same thing it's just from a different place okay the next thing that that comes up the big one that comes up is the way they look okay so like i said both of them are widget-based libraries they're meant to make the gray box sort of applications okay not your spotify okay not like that um however let's talk about tk enter it gets a lot of flack for the way it looks and out of the box the default widget set looks pretty bad honestly it looks like 1990s unix i mean that's kind of charming in a certain way if you like retro stuff but most people don't want retro there is a separate widget set called ttk which most people nowadays if they're going to use tk enter they're using ttk and that brings it up at least to looking early 2000s-ish depends on your platform it's themed differently from mac windows and linux and you can do a lot of adjusting on tk enter i think a little bit of padding and fonts colors goes a long way with tk enter you can make it look decent but there are some limits it doesn't support gradients for example it's just raster graphics there's no svgs no scaling vector graphics there's no animations so if you want swooshy controls fading in and out and stuff like that it's not going to happen and you know the other frustrating thing about it and i'll get more into this later is that styling your widgets is just kind of inconsistent you kind of do it one way with this widget a different way with this set of widgets it's a little bit kooky um pi q on the other hand out of the box default widget set i mean there's only one but the default widgets they look professional they look relatively modern some people would say they look out of date but you know i'm old so to me 10 years ago is not out of date you can style them with a syntax that's very much like css it has gradients transparency animations vector graphics you can even do opengl in a widget you know and i believe pyq six that just came out last month i believe it supports vulcan if you know what that is it's the new thing to replace opengl apparently and you can dig in and completely customize your widgets in any way you want so really if your pie cute application doesn't look modern in your eyes it's your own fault you have all the options there to do whatever it is that you need i mean a lot of people will just say well t cantor looks old and dated and pie cute looks modern i mean you can make both of them look good pie q just gives you a lot more options and makes it a lot less work okay let's let's talk next about how the underlying of the original languages for these toolkits affects them so tk enter like i said comes from tickle teak wikipedia tells us that tickle teak is a high level general purpose interpreted actually by code interpreted dynamic programming language designed with the goal of being very simple but powerful sound like anyone we know yes it's very much like python at least in what it intends to do uh syntax wise it's quite a bit different it's a little bit more like bash in my opinion than like python but it has some c constructs as well everything in tickle teak is a string so that's interesting so you can manipulate things as if they were strings even if they aren't unlike python it's not actually a garbage collected language meaning it doesn't clean up after itself but apparently the way that it works and the way that you use it that doesn't really even matter because you don't create garbage is what they say not sure how that works um but i'll i'll take their word for it um it originated like python on unix in the 90s and it inherits a lot of that culture so it's it's a good fit for python and so you don't often run into the tickle takes side of tk enter when you do it's pretty straightforward i i think it's not a big not a big deal cute on the other hand is made in c plus plus and c plus plus is very much not like python at all it's compiled it's type safe it's not garbage collected it's heavily object oriented which you know python is object oriented to but you can kind of pretend it's not if you want to now cute itself is a framework that aims to make c plus a much higher level language so it's kind of like a standard library for for c-plus plus that includes a gui framework it includes its own garbage collection for cleaning up unused objects it is very object-oriented very heavily object oriented everything that you do in cute gets wrapped in an object so uh you know for example if something takes a size you know like a pixel size you're not just going to hand it a couple of integers in a tuple you've got to wrap that in a cue size object if something needs a color you're not just going to give it you know a color string or a hex string you've got to make a cue color object and pass that into it everything's got a cue something you're going to want to rip the q key off your keyboard if it doesn't fall off if you're programming in pi cube for any length of time there's always some little q object oh i gotta you know create the q object and there's flags and there's enormes it's just it's it's a very different kind of vibe from what you're used to as a python programmer and i'll give i'll give riverbank this they they do a good job of hiding a lot of that at least definitely a better job than they used to i remember back with pi q4 you never knew if you were going to get a python string or a q string or you know a python list or a cue list you didn't know what was going to come back from a function so you kind of always had to worry about that they've done away with all that everything that can be a python object is but there's still a lot of things that you know it's um a lot of cue this and cue that it's very object oriented in that way and occasionally very occasionally you're going to run into memory management issues it's not often but every now and then there'll be a situation where either the python object or the the c plus plus object gets deleted when it shouldn't be and that has an impact on your code next difference i want to talk about is the size of these libraries first off just the physical size on disk tk enter you're talking less than 10 megabytes it's pretty small a tickle teak on my computer is about five or six megabytes in size and tk enter itself is built into the standard library so if you've got python it's there anyway pi cubed on the other hand cube itself is about 65 megabytes piqued is about 30 on my computer maybe different on yours just if you're on a different platform where it's packaged differently and that doesn't include any of the extra libraries or dependencies or anything like that now does that matter in the days of i've got a two terabyte hard drive or whatever not in terms of hard drive space but if you are for example compiling with like cx freeze or pi installer an application for download that means bandwidth where i work i've got a piqued application that people load up over the network over a unc path and every time they do that's more data they've got to download over our wan so sometimes that is kind of slow as far as the size of the library in terms of complexity enter is pretty small it's just a gui framework nothing else it's i don't know a few dozen classes maybe and you'll mostly just work with a small core of them it's got a lot of funny little nooks and crannies from the last 30 years or so that it's been around and lots of craft you can just kind of ignore so it's pretty small and pretty easy to to keep inside your head um pie cute is hundreds maybe even thousands of classes it's it's massive you can go look at the the listing of cute classes on their documentation it's it needs a search engine literally they have a search engine on the site because it needs it um it's not just a gui framework it's a second standard library it has a threading module it has a network stack it has a sql interface it has a unit testing framework i mean it's got everything it even has its own you know string and list and thing types you don't deal with that in pi cute anymore like i said um that's all abstracted away thank you riverbank um but it's still huge and you have to deal with a lot of those modules not all of them but you're going to spend a lot of time searching documentation if you're using pyqt speaking of documentation let's talk about that next because this is a place where i think both libraries have a little bit of a problem so tk enter tk enter does have some documentation an api reference basically in the python documentation in the official standard library docs there's an api reference but last time i checked and i may not be up to date on this the reference itself claimed to be somewhat incomplete and it is um if you start googling you'll probably run into a site called tk docs which is great it's a nice tutorial for using teak in several languages including python and it's also incomplete there used to be a reference for an older version of at new mexico tech and that's gone but i believe somebody has it now as a github io so you'll probably run into that if you're googling for uh tk inter documents um we used to have a site called fbot eff bot and they used to have a reference but that site seems to be down now and my experience in researching tk inter is that all of these different resources they all have information the other ones don't which leads me to believe that none of them are really complete there's just not a good go-to resource that i say oh if i need to know something about tk inter i'm going there i mean half the time i end up either at stock overflow or in the source code itself trying to answer a question which hey at least the source codes out there on github you can look at it now pi q has its own set of problems with documentation the documentation for pi cute itself is mostly focused on what pi q does in other words the the wrapper portion of it as far as a detailed api reference with how to use this class and how to use that class and you know what are all the arguments we don't really have one for pi cute what we have is the cute documentation which is for c plus plus so if you are a pi cube programmer you kind of need to learn to mentally convert c plus plus to python you kind of get a knack for this after a while but there are times when it's really not clear how you take this c plus information and utilize it in python fortunately for us pi side is now a thing and this is relatively recent that they've kind of picked this project back up and gotten it going and they are developing documentation i haven't checked that documentation in a while it may be more complete now than it was but i believe it's still kind of a work in progress but that's still a super great resource for those of us writing in pi cute all right next thing is how do we move data around in these frameworks because there's a slightly different way that each one of them has tk inter has this really cool thing called control variables and what they are are special classes that you can use to do a two-way binding between widgets and you can put traces on these variables to see when they're written to or when they're read or when they're deleted and that allows you to sort of shuttle data around your app and respond to changes in data pyq doesn't have anything like that so it's just kind of one of those cool features of tk enter what pi cute has to get data around is signals and slots which is also a really cool thing that i kind of wish tkinger has it kind of halfway has it but doesn't really have it signals and slots are ways that you can fire off custom events and include data with those events just any arbitrary data you want and it's really cool it's a great way to organize your classes keep things decoupled and get data where it needs to be in your application which if you're new to this that may not mean much to you but as you get to developing larger and larger apps this is a big problem of how do i get this piece of data where it needs to go at the right time so anyway two different mechanisms that leads you to coding things slightly differently in each one next up let's talk about the selection of the widgets that are available tk enter has not a lot of widgets and most of them are really pretty bare bones um you only have very limited support for things like rich text there is no html support of any kind no multimedia widgets there is no 3d rendering like i talked about opengl stuff even some very basic things like a date widget a time widget a calendar widget missing now some of these things you can get from third party repos some of these things you can build yourself and i go through that in my book to a degree but there there is a point where you just kind of i mean you're not going to build a web browser right no you're not going to do that in tk enter um you're not going to build a multimedia widget in tk enter okay pycute on the other hand has everything if you've seen it in a gui pi cube probably has it they've got a full on rich text editor with syntax highlighting they've got multimedia widgets you know if you want to playback video or audio they've got like i told you earlier opengl and vulkan so you can do 3d rendering right on your widgets there's a graphics thing for 2d animation you've got a charting library you can make charts you've got a full chromium browser right this is the the open source component of chrome full on basically chrome browser in a widget so you can make your own browser right you can display html with javascript and css and all the goodies yeah so if you've ever seen it in a gui pi cube probably has it almost certainly the last difference i want to talk about is the learning curve or more generally the developer experience and this is going to feel a little negative and i want to be clear here that i'm not running down either of these libraries but let's be honest nothing is perfect and at some point you're going to get frustrated with anything you work with um and i'm going to just tell you this is kind of where the frustrations come in with each of these libraries because they're both frustrating in their own way but they it's a little different um so tk enter starts out super easy to use i mean you go look up a tutorial for tk enter you'll be using it within five minutes it's super easy for any python programmer you can write procedural style code you don't have to get object oriented and i think that's something that a lot of people really like and it's just very very gradual learning curve and then you hit a speed bump and what that speed bump is going to be is you're going to think hey i want to do this thing that i've seen in like every gui ever since xerox star you know and it's not going to be there you're like there's not a widget for this there's not a way to make this widget do this thing that i think every widget of this sort off to be able to do and so you're going to start searching you're going to start looking up stack overflow posts and old forum posts and google network news posts and all kinds of things and you're finally going to find the answer and it's going to be this weirdo work around that involves making a custom class and wrapping this widget inside that widget in just the right way and and i'm talking things like having a number widget that only takes numbers or having a frame that scrolls when its content exceeds its size just little weird things that for some reason are missing from tk enter that you would think just should be there um and that is where the learning curve kind of starts to go up for tk enter when you start getting into those details of wanting to make your application behave like an application probably should these days and that kind of repeats and repeats and you'll run into that situation again and again and again and again so that by the time that you get to a complete mature tk enter program that really acts like you would expect it to your code is going to be kind of ugly a little hacky not terribly elegant and you can mitigate that some if you're good and if you are disciplined and try to do things the right way but it's just a fact that you know tk enter your you feel like you're fighting it after a while to get a modernish experience for your users but that said it's perfectly functional for a lot of use cases and it's very easy to get it going and it's very small so as long as you're happy with it it's good the pie cute learning curve is quite steep it's not impossible you're smart you can figure it out you figured out python you can figure out pi cute but if you're not down with object oriented programming and with writing your own classes and sub classing you need to get a handle on that before you do pi cube or while you do pi cube one or the other because it is just a library that is meant to be used in an object-oriented way and i i don't know why but i know some python coders just fight that they just don't want to admit that they need to make classes and they take pride and you know i have never had to write a class and i've been using python for a thousand years well if you want to use pi cute it's time to write some classes that's just how the library is meant to be used you're supposed to subclass stuff override functions build things on a q widget subclass whatever that's just how the library is meant to be used and you need to get comfortable with that if you're going to use it so that learning curve is pretty steep for some people there's a lot of c plus plus isms like i said you do have to kind of learn to translate from c plus plus to python um and like i said even memory management comes into play type safety comes into play but all that said at some point if you keep at it you'll get it right you'll kind of get the vibe of pi cute you'll say oh here's a situation where i need a cue what's it to wrap this data in before i pass it with this enum value to this constructor i mean you get it after a while but there's there's just a steep learning curve and once you get there it's kind of all the same after that and you know you have access to this huge library of really cool stuff but you just kind of have to get to that point and it takes time it's it's a tough learn um and i feel like if you learn to do it right and you can certainly still do it wrong but if you learn to do it right with pi q you can definitely write more elegant code you can keep things decoupled and keep your concerns separated and just write nicer code although probably more verbose code because you got to deal with some object oriented fussiness here and there okay so which one is better well there never is a better is there it just comes down to which one is going to meet your needs which one should you use i would say this use tk enter if number one licensing matters number two pi cute is just too intimidating for you no need to like you know not do anything because pie cute is too hard just jump in with tk enter use it when the distribution size matter if you've got something that's going to be downloaded over a network uh use it when you don't need anything fancy because it's probably not going to look fancy unless you work really hard use pie cute if you're cool with the gpl license or if you've got the money to purchase a commercial license uh use it when you want pro looking results right out of the box you just you want it to look like a professional program um without a lot of effort use it if you are okay with programming object-oriented programming if you're not you're gonna have troubles with that a lot of troubles uh use it when you need some of those advanced widgets if you need the multimedia widgets or the web rendering or the syntax highlighting or or the rich text or whatever it's all there it'll be ready for you to use now you're saying to me i'm not down with either one of those lists are there any alternatives there certainly are and the only reason i'm comparing these two is one because they're the most popular but more importantly because i've written books on these two and i feel qualified to talk about these two and i'd like you to buy one of my books but anyway if you're not into either tk enter or pi cube for whatever reason uh there are a few more options and i'm going to give the caveat that i'm not an expert on any of these i have probably gone through the elementary tutorial on them and that's about it but we've got wx python which is a wrapper for wx widgets which is another c plus plus framework it's also lgpl just like pie cute it's been around a long time it's probably about as old as tk enter but it is probably developing a little bit faster tk enter is not really being developed much it's being developed but just not very quickly now i'm told and i don't remember where i heard this but apparently uh guido van rossum the creator of python said that if he'd known about wx widgets back in the 90s that it may have been in a standard library instead of tk enter i don't know if that's true it seems plausible they seem very comfortable in a lot of ways it doesn't seem to be quite as comprehensive and vast as pi cute but it does seem a little bit more capable than tk enter it seems like it's got its act together just a little bit more okay the next alternative is kivy k-i-v-y and that is something pretty new it is actually a native python toolkit which is pretty awesome i'm glad we see glad to see we're actually getting one uh it's mit licensed it used to be lgpl now it's mit so it's very permissive which is pretty cool and it is designed for modern webby mobile kind of interfaces in fact it can be compiled to support mobile if you want to support android or ios um i have tried to learn it it's kind of a different paradigm it uses its own declarative domain specific language for gui building um it's kind of a different thing it's really cool i suggest you look into it if you're interested in that kind of thing but know that it's it's probably got its own learning curve there's also pi gtk which is the python bindings for gtk it's mostly used on linux it's lgpl i for whatever reason i don't see people using it a lot now on linux gtk is super popular and if you're writing for a linux desktop like gnome or mate or cinnamon then you probably you know will be interested in pi gtk but i don't see people using it on other platforms even on linux most people would probably use cute for developing small apps um yeah it's an alternative uh last of all i have to mention it i don't know that it's really an alternative to gui's but web technology web frameworks um when you bring up guise a lot of people will say oh just learn django or just learn flask make it a web thing and of course you can wrap your web apps in electron or something like that and make them into desktop apps that's what spotify does or visual studio code lots of things now that's definitely an option i've written a lot of web code in my life it's my bread and butter at work but it does have a significant learning curve if you don't already know html css javascript it's kind of a whole world of its own it's a totally different paradigm if you're interested in actually just writing desktop gui apps and you are starting at square zero you just know python and nothing else don't don't go there just don't don't go if you want to write web apps absolutely it's a great it's a great skill to have it's a very valuable skill to have it's not the shortest path to get you to a working gui for sure so there's that um but yeah that's my comparison tk enter versus pi cute hopefully you learned something if you have any questions feel free to leave them in the comments i'm sure i didn't think of everything once again be sure to check out my books if you're interested in either one both available from packed publications you can get them on amazon o'reilly anywhere find books on programming are sold so peace y'all god bless
Info
Channel: Alan D Moore Codes
Views: 23,456
Rating: 4.9611177 out of 5
Keywords: Python, GUI, tkinter, PyQt, comparison, GUI Frameworks, Kivy, wxpython, gtk, qt, Tcl/Tk, software development, apps
Id: Dby5jRoENlI
Channel Id: undefined
Length: 38min 11sec (2291 seconds)
Published: Thu Feb 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.