Buttons - PyQt with Python GUI Programming tutorial 3
Key Takeaways
This video tutorial demonstrates how to add a button to a PyQt GUI application, including event handling using QT Core, and basic resizing and positioning of the button.
Full Transcript
what is going on everybody Welcome to part three of our python with pqt for creating goys tutorial video series in this video what we're going to be doing is adding a button to our Windows the first thing I always think of when I'm creating Windows is okay how do I add a button so that's what we're going to talk about next so to add a button the first thing that we're going to have to also import is going to be QT core now in theory we could actually add a button without QT core we just need the QT goey to create a button and make it do like button presses and stuff but to make it actually do anything like you know have any event handling we use QT core so once we have that we're ready to move on now uh just a quick note about our um structure here so the init method what it does is it runs every time it's the initial thing that runs every time we make an a window object this in it is going to run so that means every time we make a window object um like we have down here this in it runs and it runs all of this code so it supers window it does set geometry 5050 500 300 does the window title window icon and it shows now uh what we want it to do instead is instead of self. show we want it to run self. home now home is in reference to a method which does not exist does it have a Que in front of it no so home doesn't exist yet so let's go ahead and make our own and so we're going to say Define uh home and pass the obligatory self and now we're going to add some stuff here so my theory here is the in it is any kind of like core application stuff is going to be here so if you have a main menu you're going to put that in the init okay that because that makes sense it's going to be there no matter what so it's almost like a template right for the rest of your your guey but the home is going to be stuff that's like um specific to that that certain page that you're on so we're going to have Define home self and then what we're going to do is we're going to have some a button so buttons are generally short-handed as BTN so we're going to follow that uh sort of principle QT gooey. qpush button and then this button has just basically one parameter that you have to put in and that's going to be what do you want that button to say we want the button to say quit so then quit and then pass self next BTN do click. Connect Now generally let me make some space so we can them down generally whenever you have an event you're going to have this dot connect and then you pass through a method function whatever so we're going to pass through um something that's already built into QT but I'll show you in the next video how you can make your own but we'll just use theirs for now QT core. Q core application so QT core Q core application. instance ps. quit so what this basically does is exits the current instance of your QE application okay that's all so it runs that and it'll go away now what we're going to do that basically defines or tells what tells uh this connect method basically what are we going to do when the button is CED and then what we're going to do is we're going to say BTN and we'll do and actually we'll just show this for now so now let's just do self. show uh empty parameters finally generally you're going to have um some sort of main Loop here so you'll see people maybe do Define Main and they run main so um or you might have like run here we'll just use run for now it doesn't really matter but you should have some sort of main kind of running app applicate or function so we'll tab everything over put this up here and then we'll call run to run and that should be it so let's make sure everything worked up to this point so here we have our button we got quit pqt touch we hit quit sure enough the application closes when we hit quit awesome so now the only other thing I want to show you guys with buttons is uh resizing so just like the window you can resize or CH choose a specific size otherwise you can use the def fault of course but let's say we want to make it 100 by 100 so we'll do 100 by 100 button and then what if we don't want it right in that corner what if we want a button. move and we'll move that button also to 100 100 so we can save and run that and there's our button in the middle it's a nice perfect square and it's 100 by 100 and again that's from here not from like here okay and then we can still quit and all that okay so that's a real simple example of implementing buttons and of course there's a lot more to go as far as creating your own methods here so that's probably what we're going to do in the next video uh and there's a couple other things with resizing and moving which we'll also cover in the next video so if you have any questions or comments up to this point please feel free to leave them below otherwise as always thanks for watching thanks for all the support and subscriptions and until next time
Original Description
sample code: http://pythonprogramming.net
http://hkinsley.com
https://twitter.com/sentdex
http://sentdex.com
http://seaofbtc.com
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: AI Pair Programming
View skill →
🎓
Tutor Explanation
DeepCamp AI