Це відео не доступне.
Перепрошуємо.
PyQt5 Tutorial - Buttons and Events (Signals)
Вставка
- Опубліковано 4 лип 2019
- This PyQt5 tutorial will show you how to create buttons and trigger certain functions to run when they are clicked. It will also show you how to turn our previous code into an OOP implementation to make things easier moving forward.
Text-Based Tutorial: techwithtim.ne...
Playlist: • PyQt5 Tutorial - Setup...
Get %30 off a GitPod.io subscription with the code: TECHWITHTIM2FQBMX
www.gitpod.io/
◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
tech-with-tim.....
📸 Instagram: / tech_with_tim
🌎 Website techwithtim.net
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-rusci. .
📂 GitHub: github.com/tec...
🔊 Podcast: anchor.fm/tech...
💵 One-Time Donations: www.paypal.com....
💰 Patreon: / techwithtim
◾◾◾◾◾◾
⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
Tags:
- Tech With Tim
- Python Tutorials
- PyQt5 Tutorial
- PyQt5
- Python 3 PyQt5 Tutorial
- Buttons in PyQt5
- Buttons and Events PyQt5
#python #pyqt5 #qtdesigner
You're a dawg for creating this content for free. You're helping so many people become better man. Thank you.
lmao bro chill it's just a 10 min tutorial
Heyy, I'm from Brazil. You speak so damn well that it feels like I'm watching a class in portuguese. Your channel's content is amazing and helps me a lot. Thanks man.
Thanks Tim !.. your tutorials are very clear, with a slow , easy & understandable English for non-native english spoken users!...
@@HalfABoolean_Studios But indian accent is really easy to understand most of the times, honestly i don't even care, they're awesome programing
Hi Tim. Your content is amazing. Easy to follow and well structured. Thanks. If this point has not been brought up, you could nest your clicked function under your window function. This way your clicked function has access to all the variables under your window function as they are in the same scope. That is if you don't want to define a class.
My gawd, even someone like me understood the concepts you were teaching. God bless you brother. I know only basics about oop concepts and yet I understood your explaination. Its people like you who make this world a better place. Thank you so much brother.
To clarify, the "self.b1.clicked.connect(self.clicked)" line is a bit misleading. Tim made a method called "clicked" referenced in self.clicked but the QPushButton also has a clicked attribute.
So, self.clicked references Tim's created method, while the .clicked attribute is built into self.b1. He probably should have renamed his method to avoid this confusion. Hope this helps someone.
thx bro
i was thinking the same... i would have rejected peer review if i got this. i'm a stickler about redefining existing names (whether that's a language keyword or in this case a method) and this is exactly why.
I guess Im asking the wrong place but does any of you know of a way to get back into an instagram account..?
I was stupid lost my account password. I appreciate any help you can give me!
@Lewis Judah Instablaster =)
@Tanner Kannon Thanks for your reply. I got to the site thru google and Im in the hacking process atm.
Takes a while so I will reply here later with my results.
This is awesome.. i know some coders directly start with 'Class' but you started from basic and upgraded to "class". This is more helpful in understanding.
you pressed the butt XD
Congrats, you've got 100 likes 🤣
We're pressing our own butts!
I wanted to say this! You stole the brilliant comment from me!
:)
Nice one pal. I was waiting for some GUI tutorial on python and yours is exactly what I was expecting from a tutorial: simple, clear and easy enough to understand (so long, at least). Keep up the good work
"Now if thats confusing.. uh.. I dont really know what to say"
Lmao
Excellent tutorial! I am a beginner with PyQt, and your videos are quick and concise, helping me to rapidly get up to speed! KUDOS!
Which "any questions" do you mean. You explained everything exactly and understandable that there are no further questions. I will follow you through the next videos and enjoy it.
I like how he explains complicated things so im actually learning form the tutorial and not just copying what he's typing
Your videos teach and explain more than all the other videos I watch. I think Im gonna have to buy a Tim mug.
😊
@@TechWithTim actually I purchased two mugs one to use and one to keep on my shelf. You're famous! Congrats on your job, try not to blow all the employees out of their socks. Not everybody can be a Tim you know.
@@crystolica6591 Haha, well I hope you enjoy the mugs!
You make the best videos. Thank you, Tim.
Hi Tim, I really appreciate all your work, you are one of the favourite UA-camrs of mine. One suggestion... Please try to zoom out ur screen whenever possible and/or use a larger font size while recording. Thanks
YOU ARE THE BEST. Tomorrow is my contest submission date and you saved my life. Bro
Nice tutorials Tim. I appreciate that you showed the raw code first BEFORE demoing the designer.
Hey Tim I feel as though you should inform everyone that if you don't tab things correctly while using sublime it can make the script fail. I spent about an hour copying your code trying to figure out why mine wasn't working, just to realize I had a few tabs off. Thanks for these videos so far!
you can pass in arguments to the function by using lambda, for e.g:
pushButton.clicked.connect(lambda: clicked("hello"))
instead of having to create classes and stuff
Thanks for your tutorial. I was eagerly wanted to learn PyQt5 but i was not having any source to learn from. Your tutorials are very easy to follow.
Robust tutorial :)
Looking forward to learn more PyQt5 from you!
In order to pass the label, you can use the lambda function and then refer it as a parameter for the function.
Thanks! Very good explanation, very clear even for me - English is not my first language.
Hey, I'm from Brazil, my english is not too good, but I can understand you perfectly, good job, thanks.
Love your tutorials!With this GUI knowledge ia am building a app to store your accounts(passwords, usernames etc) iwth facial detection to login in.
saved my life, thank you
This is a great video.
Your tutorials are so useful and clear and easy to follow. Great work, man! Thank you so much!
Thanks. I want to try something new and thanks for this. I love you
Atlas
Found a perfect tutorial series for myself
Tim, you are my Python professor. I learned a lot from you. Thank you very much.
And would you please make a video about how to make a stand-alone executable file out of a whole project?
I believe he already has a video about PyInstaller, but I'm not sure.
@@imaginaoUA-camsoquecomarrobas it isn't pyconverter, it is pyinstaller
@@MananGandhi oops...
With you programming becomes complicated.
Without you programming is easy.
Awesome vids. Simple and efficient.
Phenomenal series, thank you so much!
thank you very much, this was very clear and concise
your tutorials are great
Thanks for yours videos they helps me a lot !!!
Nice tut
Dude, just subscribed to you.. you explain shit perfectly... Keep it up.
good first tutorial Tim
HELP When I run the exact same program @ 1:53 it says this:
'PyQt5.QtCore.pyqtBoundSignal' object has no attribute 'connnect'
very very good . thanx
In the next video you will show us how to change the button's position?
that's amazing, great thanks!
Thanks!
Could you do a tutorial on docker after this series. I would really appreciate it because there aren’t a lot of tutorials on docker and you can explain things really clearly and effective.
very good tutorial
Damn, interesting.. thank you for the tutorial
hi
Nice video man 👍
hey Tim, thanks for putting in the effort on explaining, how python and qt works.
After following the tutorial, everything works fine, except that MyWindow doesn't refresh without focusing another application on my Mac first, so even if the event of the clicked button is recognised accordingly which can be seen with print in terminal, the button / labels do no show the new values. Switching to Safari and going then back to the Python Application, the label shows the new value.
Do you have any idea, why it doesn't refresh on the button event?
Hey man, have you figured out the solution? I'm still having this problem and can't seem to find anything about it. Thanks a lot.
same issue =.=
It's a known problem of PyQt5. Add self.label.repaint() after self.label.adjustSize() within update function
Thanks Roberto Picco! Worked like a charm!
@@robertopicco1972 Thank you! This fixed my issue.
You're awesome! it was great.
a very usefull information!!!
Gracias Tim.
thank you so much for doign this
dude.. can u help me out.. i mean like.. some tips and resources ... on how you self study .. a video maybe? please? .. it'd be really helpful.
thank you
great video!!
You are the best.
I get warning for defining instance attribute outside the __init__ function by pylint, maybe you need to put them back to the __init__ function to follow best practice.
Hi Tim, can you make a video on how to resize a QMainWindow or a QWidget class to fit the dimensions of the screen being used(since every monitor has different dimensions) without inserting a layout to the widget.
Hey Tim! first of great video, I had this one question, say I wanted the label to change text once again, that is upon a second click I wanted it to display some other text, I tried connecting it once again but a single click directly leads to the second click's text and basically ignores the first one.
Hi Tim, your videos are great, and y ou are an exceptionally talented young man. My question is....how do you personally go about learning this stuff? Do you read through the documentation on the PyQt website? Follow other tutorials? I'd love to learn the same way you learn.
W3 SCHOOL
Great video !! Why does the label x and y seem to change when you click the button ? It looks like the new label shows a bit higher!?!
Where did this "connect" came from? I tried using DIR, HELP, searching the documentation etc and i didn't find it. Thus, PyCharm won't auto-complete this. (Really beginner here sry)
I am not familiar with PyQt but the documentation states, that QPushButton inherits from QAbstractButton, which inhertis from QWidiget, which finally inherits from QObject. The decription from QObject says, that you can connect or disconnect signals to a slot via the fucntions connect() and disconnect(). The documentation of QAbstractPushbutton lists the Signal clicked. I guess this is where the function connect derives from, but I am not 100 % sure. You can probably connect to different signals to the button in the same way. I.e.: "self.b1.pressed.connect(self.OnPressBtn)" or "self.b1.released.connect(self.OnReleaseBtn)" calling different methods for pressing and releasing the button.
The documentation also has a chaoter about Signals and Slots, where the method connect() is described. www.riverbankcomputing.com/static/Docs/PyQt5/signals_slots.html#connect
Nice video. What color theme are you using if you don't mind my asking?
Can I use PyQt to create a simple iPhone app with Python code?
Pozdrawiam Pana Piotra Kozierskiego :)
Hi Tim, there is a error I got when close windows click over "X" right up window:
An exception has occurred, use %tb to see the full traceback.
SystemExit: 0
c:\users\danni\appdata\local\programs\python\python37-32\lib\site-packages\IPython\core\interactiveshell.py:3304: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
thanks mate, can you make more videos' on this GUI please
from where did you learned PyQt5?
which python interpreter are you using?
How are you going to place widgets, in the first video you said that we can do this by using our mouse but it seems like you are going to use commands, and there is a question: Why are using Qt if there is Tkinter? As a beginner, I'm a little confused)
Don’t worry the next video will clear things up
PyQT
- is more modern Looking
- You have QT-Designer, so that you can do the main Design of your GUI with a nice little tool. (See next Tut)
- It is Possible to use QML - QTMarkUpLanguage so that you can Style your UI the way you want (flat Design and so on)
-You can Use QT with C++ (what it was written for) so if you are later learning C++ you dont need to learn a new UI-Framework
- In General QT has more functionality (Charts, SQL, Touch Display...)
- LG uses QT for thier TV GUIs ( ua-cam.com/video/VXjS_GQmBa0/v-deo.html )
Okay if you want a Car GUI - QT is the way
blog.qt.io/blog/2019/06/28/announcing-qt-automotive-suite-5-13/
I think Tkinter is fine for small Projects if you need something larger and more modern QT is the way.
@@Lofwyrf Thank you. Your answer is the most useful I've seen so far when it comes to PyQT vs. Tinkter.
@@BiancaAguglia ur welcome
Heh hehe hehe "You pressed the butt"
How to Add buttons via with at method? To Create a dynamic UI?
Nice Vid btw :)
when adjusting the window, labels and buttons doesn't get readjust
so that's what i'm dealing with right now
any kind of solution?
Can someone explain b1.clicked.connect(clicked)
is connect() a function or a method? which class is this found under?
Well, "clicked" is an event, so my guess is that there is some sort of event/signal class and that "clicked" is an object of that class that the button happens to have a variable for. So that would make it a method.
If you have already imported QtWidgets from PyQt5, why are you importing QApplication and QMainWindow separately?
Does this app run on Android?? Thanks, your tutorials rock.
But if i use qt designer app then what should I do?
Although all the OOP stuff is great, it seems to me that you would have to keep doing this labor intensive work every time you used Designer to tweak your GUI. Could you somehow pass the reference to QMainWindo ("win") to other methods that need access? Actually.... I'm not even sure if b1 is a member of the win class.... so maybe that won't work.
i'm usually a Tkinter guy, but the crispness in PyQt5 though...
Add action to a button 01:04
Hi Tim! I have a pushButton that calls a function to print something. When i click the pushButton i get a small delay before the function is called, do you know why??
edit: id like it to be instant.
global label
label.setText...
that would also work hehe
When I made the code for the button and then press play, it gives me a syntax error. Any reason why?
How about certein right clicked event connected to certein button
so if we have multiple buttons we have to create separate update functions for them?
I got "Process finished with exit code -1073740791 (0xC0000409)"
Tried to fix it but couldn't do it, hopefully, it won't ruin the next tutorials.
Same, are you using PyCharm?
My label's text won't change, and I have the exact same code as you. Please help me out.
Same. Did you fix it?
same here, I tried to copy and paste his exact code but it doesn't work either, I am on Mac if that makes a difference
@@IsaacYongMusic me too I'm on a Mac
@@harmannatsingh3933 I just figured it out! In my case I see that if self.label move() is active, it will not updated. And the solution is to add self.label.repaint() after teh setText. Let me know if that helps!
Thanks to the gentlemen in the comment section.
@@IsaacYongMusic thanks it works!
Hi, thank you for sharing, please, what about if I want to button to behave like a calculator, when I click it shows up the number in a separet windows? Sorry for my broken English, Iam angolan and we Speak Portuguese.
Hey guys please how i can make this button work more times ? I mean click button 3 times and label will change 3 times to something else. Is that possible ?
Yeah That's simple. For eg- > self.label.setText(str(random.randint(0,5))) will show a new value b/w 0 to 5 in label each time button is pressed or Just store a value in a variable and update that variable to a new value each time button s pressed.
Next tutorial on pwa with python or python with react/react native☺️☺️ great work👍
How do I use this for an exit button?
os.system(cmd)
QtCore.QCoreApplication.instance().quit()
OR self.close() don't seem to work when put into def quitAction(self) and invoked through quitbtn.clicked.connect(self.quitAction)
What is the difference between:
super(Myw=Window,self).__init__()
&
super(QMainWindow).__init__() ?
thanks.
if i edit the UI in designer, does the code in python file change too?
Hey! I have a little problem here : self.b1.clicked.connect(self.clicked()) its not working for me just with lambda ( self.b1.clicked.connect(lambda : self.clicked())) without lambda I get an "argument 1 has unexpected type 'NoneType'" error message. Anyone know why?
if you think Tim's video is not enough try reading the documentation, it have a lot more fun stuffs in it. www.riverbankcomputing.com/static/Docs/PyQt5/index.html
Hi Tim, thanks for your python tutorials that help me and my team to learn it in simple way.
I am facing problem with 'designer'. I did pip for PyQt5-tools l, however 8 did find the designer under folder. Please help.
C:\Users\*****user name***\AppData\Local\Programs\Python\Python36\Lib\site-packages\pyqt5_tools\Qt\bin
Hi Tim . Your videos are awesome, but I am having an issue in running the code in Python 3.7, Microsoft Visio. I am using Pylinter here. The error I am getting is " illegal target for annotation python(parser-16) 3.7" near self,
def__init__(self):
super(MyWindow, self).def__init__()
self.setGeometry(100, 100, 300, 300)
self.setWindowTitle("Roy's Test")
self.initUI()
please advise