PyQt5 Tutorial - Setup and a Basic GUI Application

Tech With Tim · Beginner ·🧠 Large Language Models ·6y ago

Key Takeaways

This video tutorial covers the setup and creation of a basic GUI application using PyQt5, a Python 3 module for rapid development of GUI applications, and QT Designer for generating code for the GUI.

Full Transcript

hey guys and welcome to a brand new tutorial series on Pi qt5 in Python now pqt is a application or a framework story for python that allows you to build gooey applications very quickly now what I'm showing you right here actually is the main kind of interface that you're going to be able to use it's called QT designer to create your graphical user interfaces now let me show you how easy this is compared to some other things that you might have tried to use before so for example Sam creating a guey I want to have a label I drag in the label I want to throw a button somewhere well we'll find a button there we go maybe we want some checkboxes we want them to be here let's throw them in right I'm just showing you how easy and how quickly you can actually design and create a graphical user interface and you don't have to go back and forth from code and modify the positions and change all of that and this is just something that's super simple and it makes your life way easier especially if you're trying to create some kind of simpler applications and you don't want to spend a lot of time messing with the graphical user interface part of it you just kind of want things to work and you know sometimes it's really nice to be able to just come into a designer drag and drop it and see exactly what it looks like without having to keep running the code and all of that so anyways that was just kind of a little bit of a tease on what we're going to be getting into in this series and we're going to be learning how to use that properly and how that actually works but in today's video we're just going to be setting up pyqt5 and creating a very basic application by just writing a little bit of code so what that Designer actually does is it generates a bunch of code for us and you pretty much just take that code and use it so you kind of drag and drop stuff it says this is the code that you would need to create that then you can use that code so anyways what we're going to do now is we need to install and get that tool that QT designer from pqt so we're going to open up a command promp and we're going to be using pip to install this now for some reason when you type pip in here and you hit enter it doesn't work that means Python and pip are not installed in your systems path so to fix this I'm going to direct you to a video I have in the top right hand corner of my my screen it's called how to install P game but it shows you how to fix your pip if it's not working so if your pip is working what we're going to do is type pip install and then Pi qt5 um don't install four is that is the one for Python 2.7 and we're going to be using Python 3 next we're going to do pip install Pi qt5 hyphen tools now this is going to give us that QT designer and a few other tools that we might want to use later on with pqt once we're done that um we're actually ready to start writing some code and pop up our first main window so let's close that and let's get into some kind of uh text editor here so I'm just going to be using subline Text Now quickly before I go on something I forgot about pqt is it is actually cross- compatible and crossplatform which means that any code you write here will actually work on Mac it'll work on Linux it'll work on iOS it'll work on Android now I'm probably not going to be showing you how to package this up for all those different os's but it's nice to know that your code will actually scale and work for any OS that you want it to anyways what we're going to do now is just type a few import statements here um so we're actually going to start with from PI qt5 make sure to capitalize that P and the Q we're going to import and to start uh QT widgets like that now next we're going to say from PI qt5 do QT widgets like that we're going to to import Q application Q main window and finally we're going to import Q actually I think that's actually all we need for that one yep and the last import statement is Sy Ys so that's all we need to import for right now later on we'll probably be importing some more things up here from pqt but to create a basic application that's all we need so when we're working with pqt the first thing we need to do when we're creating an app or creating a gole or whatever it is is Define an application so what we're going to do is create a function that's going to do this for us and we'll just run that function at the end of our code so I'm going to call this function window and inside of here what I'm going to do is just say app and that's going to be equal to Q application now this is where we always have to start off some kind of application and what we need to do is we need to pass sy. RGV inside of here now I believe what this is doing and I could be incorrect is just giving some kind of config setup for a q application so it knows what OS it's running on kind of how to display the window because based on what OS you're running um there's going to be some differences right so that's kind of what this is doing just getting our application set up you don't have to worry about it too much the next thing we need to do is create some kind of window or some kind of widget that we're actually going to show in our application so in my case I'm going to use Q main window but you may see some people in tutorials using Q widget uh it's kind of similar but we're just going to use Q main window so what I'm going to do here say um wi equals in this case Q main window like that all right so the next thing we're going to do is actually set the size and title of our window so if we want to set the size of our window and actually the position of it on the screen what we need to do is call a method called set geometry so we're going to say Geo geometry I think I spelled that correctly and then inside of here what we're going to do is give four arguments the first one is going to be the exposition the next one is going to be the Y position and the last two are going to be the width and the height now the X position actually stands for where on your screen you want to show up so if I put this to zero and I put my y position to zero what's actually going to happen is our window is going to show up in the top left hand corner of your screen now if you set this to let's say 1920 by 1080 it's going to show up in the bottom right hand corner of your screen and you actually won't be able to see it now let me just quickly illustrate how this actually works so that any of you that don't understand this coordinate system kind of can get this pretty quickly so this right here is actually in computers typically when we're doing Graphics is actually 0 0 now excuse me cuz I'm wrong with my mouse so this is kind of difficult to do um so what happens is when we say something like 100 100 we're going to go 100 pixels this way and then we're going to go 100 pixels down now since we're starting with the top leftand corner what that means is this window will now be moved um oops I don't know how that happened um so it looks more something like that so we're going to move the top leftand corner of the window to be at position 100 100 and that's going to go for all of our widgets as well let's say we place a widget inside of our window at maybe like 50/50 well the top leftand corner of that widget will be at 50/50 which is something that's important you're going to have to account for when we're kind of moving and placing things so hopefully that makes a bit of sense so anyways I'm just going to set mine arbitrarily to be like 200 200 and then for a width and a height let's go with uh 300 300 awesome so now that we've done that we're going to set a window title now this is what's going to show up on the top little bar you can see like up here this is what the window title is kind of for my subline text um similar thing here for the pqt so we're going to say win. Set uh window title like that and then here you name whatever you want so in this case I'm just going to say like like Tech with Tim which is the name of my channel and now what I'm going to do is actually put some stuff inside of our window now before I do that I want to show you what this looks like so you can get an idea and then we'll start adding some things so to actually show our window we need to call window. show and after that we need to write this one line that looks a little bit confusing but essentially what it's going to do is make sure that our window shows up nicely and we'll exit when we click the x button you don't have to read too far into it but it just means that we get what's known as a clean exit so I'm going to do sy. exit app.exe like that now again this just means uh we're waiting for this Q application to exit and when that happens then we're going to exit and close the application so let's run this program now um oops I got to actually call this function if we want anything to show up so let's do that at the bottom of our program and you can see we get Tech with Tim we get a window that let me run again that initially showed up at what I say 200 200 with height and width 300 300 now if I change this again to be like 1,000 you can see that now the window is showing up further so it's actually useful and you can pick kind of where you want it to show up so anyways this is kind of boring we need to add some stuff into our window and look at it so what I'm going to do is actually just create a label and throw that label on our window and then we're going to end the tutorial there so if I want to create a label what I'm going to do is say label equals in this case QT widgets. Q label I hope you guys are noticing that everything kind of starts with Q here and inside of this what we're actually going to do is say where we want this label to be a little bit confusing because sometimes people want to put what's on the label but what we're going to do is set window because that's where it's going to be showing up next we're going to say label. set text and this is where we can change what it actually says so in this case we'll just say my first label like that okay so now that we've done that we can move the label uh if we'd like to do that so to move it we can do label. move and with move this we'll just take an XY position and it'll move it there so let's say we want to do 5050 remember that's from the top leftand corner so down 50 um to the right 50 and that's where the top leftand corner of our widget will be so let's run this and see what we get and we get my first label positioned at 50/50 again you can see it's that top left hand corner and that's inside of our main QT window so anyways that has been the basics of setting up pqt getting a very basic window going here I just showed you the label widget in the next videos we'll go in uh more depth we'll do a few other different things with this and then very shortly we'll get into the actual QT designer um talk about how that works and how to use the code that it generates in our actual uh application here we're going to start kind of basic um and just build our way up and if you guys have any recommendations of stuff you'd like to see definitely leave it in the comments down below with that being said I will see you guys in the next video

Original Description

PyQt5 is a python 3 module that allows for rapid development of GUI applications using its built in program Qt-Designer. PyQt5 runs on all operating systems which means all of the code you write will scale. This tutorial series will focus on the basics of PyQt and creating useable GUI's. In this video I discuss how to download and install pyqt for windows and setup a basic gui application. Playlist: https://www.youtube.com/watch?v=Vde5SH8e1OQ&list=PLzMcBGfZo4-lB8MZfHPLTEHO9zJDDLpYj Text-Based Tutorial: https://techwithtim.net/tutorials/pyqt5-tutorial/basic-gui-application/ Get %30 off a GitPod.io subscription with the code: TECHWITHTIM2FQBMX https://www.gitpod.io/ ◾◾◾◾◾ 💻 Enroll in The Fundamentals of Programming w/ Python https://tech-with-tim.teachable.com/p... 📸 Instagram: https://www.instagram.com/tech_with_tim 🌎 Website https://techwithtim.net 📱 Twitter: https://twitter.com/TechWithTimm ⭐ Discord: https://discord.gg/pr2k55t 📝 LinkedIn: https://www.linkedin.com/in/tim-rusci... 📂 GitHub: https://github.com/techwithtim 🔊 Podcast: https://anchor.fm/tech-with-tim 💵 One-Time Donations: https://www.paypal.com/donate/?token=... 💰 Patreon: https://www.patreon.com/techwithtim ◾◾◾◾◾◾ ⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡ Tags: - Tech With Tim - Python Tutorials - PyQt5 Tutorial - Python PyQt5 Tutorial - PyQt5 Designer #python #pyqt5 #qtdesigner
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Tech With Tim · Tech With Tim · 0 of 60

← Previous Next →
1 A* Path Finding Algorithm(Visualization)
A* Path Finding Algorithm(Visualization)
Tech With Tim
2 Python Programming Tutorial #1 - Variables and Data Types
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
3 Python Programming Tutorial #2 - Basic Operators and Input
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
4 Python Programming Tutorial #3 - Conditions
Python Programming Tutorial #3 - Conditions
Tech With Tim
5 Python Programming Tutorial #4 - IF/ELIF/ELSE
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
6 Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
7 Python Programming Tutorial #6 - For Loops
Python Programming Tutorial #6 - For Loops
Tech With Tim
8 Python Programming Tutorial #7 - While Loops
Python Programming Tutorial #7 - While Loops
Tech With Tim
9 Python Programming Tutorial #8 - Lists and Tuples
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
10 Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
11 Python Programming Tutorial #10 - String Methods
Python Programming Tutorial #10 - String Methods
Tech With Tim
12 How to Overclock a NVIDIA GPU
How to Overclock a NVIDIA GPU
Tech With Tim
13 Python Programming Tutorial #11 - Slice Operator
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
14 Python Programming Tutorial #12 - Functions
Python Programming Tutorial #12 - Functions
Tech With Tim
15 Python Programming Tutorial #13 - How to Read a Text File
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
16 Python Programming Tutorial #14 - Writing to a Text File
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
17 Python Programming Tutorial #15 - Using .count() and .find()
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
18 Python Programming Tutorial #16 - Introduction to Modular Programming
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
19 Python Programming Tutorial #17 - Optional Parameters
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
20 Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
21 Python Programming Tutorial #19 - Global vs Local Variables
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
22 Python Programming Tutorial #20 - Classes and Objects
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
23 Cool VBS Script to Prank Your Friends!
Cool VBS Script to Prank Your Friends!
Tech With Tim
24 How to Overclock an AMD GPU
How to Overclock an AMD GPU
Tech With Tim
25 Best GPU'S For Mining Ethereum (2018)
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
26 Recursion and Memoization Tutorial Python
Recursion and Memoization Tutorial Python
Tech With Tim
27 Ethereum Mining Rig - Hardware Guide
Ethereum Mining Rig - Hardware Guide
Tech With Tim
28 Pygame Tutorial #1 - Basic Movement and Key Presses
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
29 How to Install Pygame (Windows 8/10)
How to Install Pygame (Windows 8/10)
Tech With Tim
30 How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
31 How to Mine Ethereum 2018 - WORKING (Super-Easy)
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
32 Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
33 Pygame Tutorial #2 - Jumping and Boundaries
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
34 Pygame Tutorial #3 - Character Animation & Sprites
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
35 Pygame Tutorial #4 - Optimization & OOP
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
36 OBS Studio Tutorial - Best OBS Settings
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
37 Linear Search Algorithm - Python Example and Code
Linear Search Algorithm - Python Example and Code
Tech With Tim
38 Make Any Mic Sound AMAZING! (WITH OBS)
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
39 Binary Search Algorithm - Python Example & Code
Binary Search Algorithm - Python Example & Code
Tech With Tim
40 Pygame Tutorial #5 - Projectiles
Pygame Tutorial #5 - Projectiles
Tech With Tim
41 Pygame Game - Mini Golf
Pygame Game - Mini Golf
Tech With Tim
42 Pygame Tutorial - Projectile Motion (Part 1)
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
43 Pygame Tutorial - Projectile Motion (Part 2)
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
44 Pygame Tutorial #6 - Enemies
Pygame Tutorial #6 - Enemies
Tech With Tim
45 Pygame Tutorial #7 - Collision and Hit Boxes
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
46 Pygame Tutorial #8 - Scoring and Health Bars
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
47 Cloud Mining vs. Hardware Mining - 2018
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
48 How to Install Pygame on Mac OSX (Fast-Simple)
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
49 Pygame Tutorial #9 - Sound Effects, Music & More Collision
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
50 Pygame Tutorial #10 - Finishing Touches & Next Steps
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
51 How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
52 How to Create a Button in Pygame [CODE IN DESCRIPTION]
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
53 Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
54 Pygame Side-Scroller Tutorial #2 - Random Object Generation
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
55 Pygame Side-Scroller Tutorial #3 - Collision
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
56 Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
57 How to Create A Message Box in Python - Tkinter
How to Create A Message Box in Python - Tkinter
Tech With Tim
58 Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
59 How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
60 Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim

This video tutorial teaches the basics of PyQt5 and how to create a GUI application from scratch using QT Designer. It covers the installation of PyQt5 and QT Designer, creating a basic GUI application, and generating code for the GUI using QT Designer.

Key Takeaways
  1. Install PyQt5 and QT Designer using pip
  2. Create a basic GUI application with a label, button, and checkboxes
  3. Generate code for the GUI using QT Designer
  4. Define an application using QApplication
  5. Create a QMainwindow and set its size and title
  6. Use setGeometry to position the window on the screen
💡 PyQt5 and QT Designer can be used together to rapidly develop GUI applications with a high degree of customization and scalability.

Related AI Lessons

I Asked ChatGPT to Fix My Life. It Couldn’t — Until I Changed One Thing
Learn how to effectively use AI like ChatGPT to improve your life by changing your approach
Medium · AI
I Asked ChatGPT to Fix My Life. It Couldn’t — Until I Changed One Thing
Learn how to effectively use ChatGPT to solve personal problems by changing your approach
Medium · ChatGPT
Claude Sonnet 5 Is Here: Why It Might Replace Your Opus Subscription
Learn about Claude Sonnet 5, a new AI model that offers near-flagship performance at a lower price, and its potential to replace Opus subscriptions
Medium · Programming
Introducing Claude Sonnet 5 on AWS: Anthropic’s most capable Sonnet model
Learn about Claude Sonnet 5, Anthropic's most advanced Sonnet model, now available on AWS, and how it delivers top-tier intelligence for coding, agents, and professional tasks
AWS Machine Learning
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →