Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Exploring GUIs and Games

GUI Libraries linked in this lesson:

Real Python GUI Resources:

Python Game Libraries:

Real Python Game Devolopment Resources:

00:00 In the previous lesson, I showed you some ways of improving your command-line interface. In this lesson, I’ll go graphical. GUI stands for Graphical User Interface, and it’s the generic term for those clickable applications found on your desktop and your phone.

00:17 The line can be a little blurry as you can use web technologies to accomplish a lot of the same thing. For this lesson, I’ll be concentrating solely on more native GUI applications.

00:28 I’m getting ahead of myself as technically this is a game, but this particular game uses a GUI engine to build it. The Tkinter library comes with Python and you can use it to create clickable things like the squares here in the Tic-Tac-Toe game.

00:44 That’s right, you don’t have to find a chicken to play with. You can play against the computer if you like.

00:51 TK is a cross-language graphical toolkit and Python includes a library for interfacing to it. The upside of this is if it has a GUI and you can use Python, you can do graphical things.

01:02 The downside is the widgets don’t tend to be platform specific, so your application will have a generic sort of look and might not be intuitive for some users.

01:12 The wxWidgets library is another cross-platform GUI toolkit that you can use, and wxPython is a third-party interface to that. There are lots of GUI libraries out there, and Kivy’s yet another one.

01:26 This platform has a wide array of clients and allows you to build stuff for multi-touch interfaces like phones and tablets as well.

01:35 QT is a dual-licensed commercial toolkit for building applications that includes tools for GUIs, networks, databases, and more. The dual license means you can do what you want if it’s an open-source project, but if you’re planning on building something and selling it, you need a license.

01:52 That said, QT is really powerful and has native-like widgets on lots of platforms. There are a couple of different Python libraries for interacting with QT, including PyQT and PySide.

02:05 And in case moving back and forth between a bunch of different GUI libraries seems complicated, PySimpleGUI is a wrapper that unifies the interface to several GUI toolkits.

02:18 There are a whole host of GUI tutorials for you at Real Python, as well as an organized learning path that leads you through your journey. In fact, there’s even a path specific to PyQT as well.

02:33 Here’s a sample of a variety of GUI project tutorials that help you practice with PyQT and other libraries. Who doesn’t love to play games? In fact, it’s a common reason for people to get into programming in the first place.

02:47 Most games require a wide variety of programming skills, so even if you’re only building them for yourself, they can be good practice.

02:57 This code’s from a course you can take, which leads you step by step through making an asteroids clone using the PyGame library. It includes how to render sprites to the screen, how to do collision detection, and even sound.

03:10 Pew, pew, pew, indeed.

03:13 The Arcade library is a great place to start if you’re writing games in Python. While PyGame is really full-featured, it’s built on top of SDL, which is a cross-platform library for rendering graphics through OpenGL and Direct3D.

03:28 Unfortunately, PyGame’s website is an abomination. Their choice of green hurts my eyes. Well worth reading, just bring your sunglasses. A third alternative is pyglet.

03:40 I haven’t actually played with this one myself, but it includes general graphical tools, which can be used to build all sorts of applications, including games.

03:50 There are several game tutorials available at Real Python, including this one specifically on PyGame.

03:58 Real Python has a lot of project-based tutorials that teach concepts about game programming and let you practice your skills. This includes a general tutorial on arcade games, that tic-tac-toe I showed you earlier, rock, paper, scissors, which is purely text-based, if you want to learn the mechanics of game coding without touching graphics, and the asteroids one that I demoed available as both a tutorial and a video course.

04:23 That’s it for section one. Now onto data science and math.

Become a Member to join the conversation.