Creating Buttons With TKinter - Python Tkinter GUI Tutorial #3
Vložit
- čas přidán 13. 01. 2019
- How to create buttons with TKinter and Python. In this video I'll show you how to create buttons with tKinter. Its pretty easy!
In this series I'll show you how to create graphical user interfaces for Python with Tkinter. TKinter comes with Python already, so there's nothing to install!
✅ Watch The Other Videos In This Python Playlist:
bit.ly/2UFLKgj
▶️ See More At:
Codemy.com
✅ Join My Facebook Group:
bit.ly/2GFmOBz
✅ Subscribe To My CZcams Channel:
bit.ly/2IGzvOR
▶️ Learn to Code at Codemy.com
Take $22 off with coupon code: youtube
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My CZcams Channel:
bit.ly/2UFLKgj bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
@poodles Game sure thing
what if the button's command is a function that requires me to send a value? I can't use the bracket cus the function will just start. How should I do it? Or if u made a video about it can u link it to me pls
@@iancheng6861 use lambdas...yeah I've done videos on it. command=lambda: function_name(pass stuff)
@@Codemycom thx thx
@@iancheng6861 sure thing
Such a friendly ,smooth and clear explanation , I'm really having fun with it. Thanks a lot.
Thank you! I appreciate that!
Thank you. I really like your teaching style. You come across as very friendly and patient. It makes me want to learn more from you.
Glad you're enjoying them!
You're kind of like the best thing that ever happened to youtube :)
Wow, thanks!
Unleash your Tech bruh, no need to use foul language
@@atakheli3608 its not me my bro he has no idea how to code in python then he learns from CZcams but makes slightest of mistakes and does this shit from my account
Unleash your Tech oh ok, hopefully he he gets better at code
@@atakheli3608 he just made tic tac toe its on the App Store I helped him a lot but yah
I just started with Tkinter today and i already know how to make a button. Good video and i think its the best explanation i've seen so far!
Good job, keep it up! :-)
Your videos are great. I love your way of teaching. Thank you so much John for providing this for free!
Glad you enjoy them!
I learned how to use Python GUI in just a few hours, just amazing.
Awesome!
I really really appreciate your content, BIG TIME❤
Glad you enjoy it!
Hi, thank you so much for your videos, they are really useful!
I love the way you explain everything.
I found it easier to write everything in Visual Studio Code and then just "run" it from there instead of using the Windows Terminal and always typing the command.
I like to use as many shortcuts as possible, I do like Sublime text too but since VS I find everything easier on it.
Glad you enjoy the videos :-)
Great lessons my friend, you're a good person!!
Thanks!
Great job deserving of thanks
عمل رائع يستحق الشكر
انا اتفق معاك
really liked the way you teaching this, when i am not broke and have extra time i will surely check out your courses.
Thanks!
loving this!
Awesome lectures, even a beautiful teacher taught amazing lessons.
Thanks!
Hi, the videos are all good, thank you very much.
thank you for this video! im doing A personal project and I rlly want to immerse myself with GUI specifically tkinter and i already have good feeling about it, thank you
Glad you're enjoying it!
thanks alot this was easy and fast to learn and i feel like i have acheved somethign, thanks!
You're welcome!
Your videso are great!! Continiues with thes god work!
Thank you so much!
What else can i say... thank you soooooo much. you the man.
Thanks!
thank you for these videos. very informative
Glad you like them!
Really useful for my next seminar in class. Thank you
Happy to hear it!
I appreciate your teaching
Glad you're enjoying it!
Cheers! For my 1st Button with you!
Awesome
This guy is seriously awesome haha
hey thanks!
very clear explanation awesome channel, I'm gonna SUBSCRIBE! and like
Thanks!
thank you so much for replying to every comment it is so cool!
My pleasure!
Thank you!
I understood very clearly
Nice
Best way to teach. Go on.
glad you enjoyed it, there's almost 200 more videos on this playlist
thank you for your help.❤❤😊
welcome
thank you so much
!!!!!
Welcome!
You actually blew my mind 😂
glad to hear it! lol
I want to add some kind of light besides a button(s) and each time the button(s) was(were) clicked the light jumps from red to green and in case an error occurs or the function couldnt be executed the light stays red. Any idea how to tackle that? Thanks a lot for the help in advance!
Now I am going to beat my friend's challenge! All thanks to god, then to you!
ha fun
I am exactly the person who you made this video for and who would change the color of buttons and make them bigger lol I am legally blind and starting to work on creating a customTkinter GUI for the visually impaired and a large orange send button would be very helpful :-) thanks for the info I'm going to watch all 200 and whatever videos lol I probably won't come up with a working app but you'll get watch time haha
Nice!
Great..Improve👍
:-)
Thanks for the vid
You bet
Very interesting. I am running this on an Orange Pi-5 Debian-Bullseye 64-bit OS. Now I need to figure out how to make the OPi5 OPi.GPIO Python3 PWM pins run the servo Pan/Tilt motors? They are a little different than the Raspberry Pi4 setup. It would be cool to control the servos with some TKinter buttons. 😎 Thank you.
Cảm ơn bạn!
Thank you🙏
Welcome!
شكرا كثيرا perfect
sir thanku that ( ) guide help me alooooot thankuuu
Welcome!
Lesson check. Thanks.
welcome
You're really a magician.
Thanks!
@@Codemycom 😊You deserve it
@@abhijitjagdishprakash4104 I appreciate it!
this guy is rock !
Thanks!
It very difficult in my country to get teachers like you....... I'm from India Love you sir
thanks for this
You're very welcome
would love to see a video on Websockets in Python via flask/dejango
I'm planning on doing a lot more flask videos soon
Thank you sir
Welcome
Button padx, pady are not to change size of button. They are to add extra padding around button text
which changes the size of the button. why argue semantics that are meaningless?
Thank you
welcome
Sir I'm Your New Student Love From Pakistan
Welcome!
Thanks. Спасибо.
Welcome
thank you
You're welcome
Is there a way to increase the feedback when you click a button? When I click a button you can barely tell that you clicked it. Thank you for all your videos :-)
Thanks to this I have a wall of buttons
awesome
thank sir
Thank you for watching!
Thank
Welcome
cool!
thanks
Do we have a way of aligning a text inside a button?
Hi Mr. Elder, thank you for these great videos. I have a problem with my code in that I can't get the background color to take effect in the button. And the button doesn't depress like it should. Otherwise, all functionality is in place.
Also I'm running on Mac OS. Thanks for any help.
What does your button code look like?
@@Codemycom have the same problem. My code is:from tkinter import *
root = Tk()
myButton = Button(root, text="Press me", fg="blue", bg="green")
myButton.pack()
root.mainloop()
i had the same issue where it doesn’t press, all you have to do is click out of the tkinter window and click back in, as for the other one i have the same issue and dont know how to fix it
i have a question, i am planning to learn to program with a desktop application as my end goal, now heres the thing, for what i need this program to do it will use SVG extensively for the main interactive aspects, its going to be based on the LCARS interface which are basically single colours and very simple shapes, my question is can it be done, if you google LCARS you can see exactley what im looking at doing, i just dont want to invest a ton of time in a pointless excersise, why have i chosen to go down the SVG route, performance for one, efficiency for another and aesthetics, i hope you can answert this question.
Sorry, I don't know what any of those things are...
Howdy partner!
Hello!
@@Codemycom I was wondering if you could please make another tkinter tutorial with the new python update
@@Pablo-fo4em what new python update?
thanks
Welcome
@@Codemycom Can you halp me in next video I write my problem into comment in next video
@@skfungaming1308 only if it directly relates to the next video
Is the a way to put a Checkmark (ALT 0252) on the button?
Is there a video in your playlist, that goes more in depth so that i can place things in my program more accurately, maybe even click and drag things into a place... maybe using coordinates or something, then you type them in? thx
sure
this is a simple way to learn python .
thanks
When using bg to change the color it isn't working for me at all; fg works completely fine but bg doesn't change anything. Do you know why that may be happening? Appreciate the videos :)
had the same problem:-(
Great tutorial, the only thing is that the fg="blue" works fine, but bg="red" does not change the button colour. Both parameters are coma separated. I'm on Mac.
You must have a typo...did you forget to wrap red in quotation marks or something? You can also use hex color codes.
Merci (:
Welcome
how to deal with the problem of button resizing with window resizing using grid?
Are you asking how to make the window bigger while the button maintains its current size?
are Button, Label and others widgets classes or functions as you are saying in this video?
they are classes
John, do you have any guide for how to make buttons the same size/center the text? I'm having a hell of a time getting my buttons to be the same size (irrespective of the text inside), even with padx...
No sorry...I mean, they wouldnt be the same size because it depends on the text and always will
@@Codemycom Okay, thanks for answering.
hey John, i just joined codemy and used the code here to get all the courses, however, i cant seem to find the tkinter in the list of courses? i'll just watch here while i wait for your response. Great content by the way! thanks!
Hey Vince...the tKinter videos are exclusively on youtube.
@@Codemycom Hey John! thanks for the response! i'll follow the training here then.. keep it up!
@@vinceantonio777 sure thing!
Hello Mr. John and everybody.
First, thank u for this tutorials. And my question : "How can i add two mission to one button. I mean, How can i add two command ? This is my question. Thank from now.
Have the button command call a function, inside that function call another function
@@Codemycom Hi sir, your lessons are extremely helpful. I watched many videos on youtube for Tkinter however, I was not able to understand them. Your lessons are very clear and concise. Just a query, can we bind multiple functions to one command?Thank youu:)
@@prithikannan8568 you can add functions inside of functions in the normal python way you call any function
Done
Can we change the shape of the button too?
Plz help....
Not really...you can use an image and then bind that to a click, but it's a hacky sort of thing...
hey, almost nothing is working when I try to change the bg color of the button-neither the hex color codes or the color names. Is there anything I might've done wrong?
Yeah, probably everything. The code must be exactly like mine...
I was wondering why when I clicked the button on a Mac, the window flickers black for a second then turns to normal. I assume that this is just the window being updated, but I was wondering if there is anyway to get it to update smoothly like on windows.
Also I can't seem to change the background color of the button and I was also wondering if that is just a system difference.
No clue what's going on there...it should be smooth
Codemy.com It seems that as I continued through the playlist, the flickering just stopped. Maybe it’s because the page was updating from the button being clicked and due to a system difference
Can we display an already stored variable using label. For ex:
var = 5
label1 = label(root, text = var)
Will it work
Or what if i want to display the variable and some text?
Yes it will work. But more importantly...you could have simply tried it yourself faster than it took to write this comment and wait for an answer. You can concatenate text = var + " some text" as long as they are the same data type (for instance, both strings).
@@Codemycom thank you sir, actually I am quite new to GUI , and just watched the first three videos, so I wanted to clarify my doubts before I started to actually code, which I shall be doing shortly
@@a_22_romitbhaumik89 cool
whats up guys. its john elder... we all come for this intro lol
haha
My button doesn't show any up or down state when I click on it. Im using the exact code in your buttons video, The command function works though. I'm using PyCharm on a Mac. Any ideas?
After more testing, I needed to add "from tkinter.ttk import *" below the original "from tkinter import *". Maybe I'm running a later version?
@@scot1711 no, version shouldn't have anything to do with it.
Your video is very well explained.
If I add a fews entries, then a value to each of them. How can I get each of the values and add them up?
Here are the codes. Thanks
from tkinter import *
root=Tk()
somme=0
def add_button():
global somme
somme +=1
for i in range(somme):
lab1=Label(root, text='lab1')
lab1.grid(row=i, column=1)
entry1=Entry(root)
entry1.grid(row=i, column=2)
bouton_add=Button(root, text='Create widget', command=add_button )
bouton_add.grid(row=5, column=0)
root.mainloop()
Keep watching the videos in this series, I go over all of that.
Even when I put in the root.mainloop(), there's no feedback when I press the button. Why? (I'm on Mac btw)
even? You always have to put the mainloop no matter what...that has nothing to do with the button. Did you give your button a command? There's likely a typo in your code
@@Codemycom Here's my code:
from tkinter import *
root = Tk()
def click():
label = Label(text = "You pressed me!")
label.pack()
button = Button(root, text = "Press me!", command = click)
button.pack()
root.mainloop()
@@_fluffyy1028 that code works fine. Are you using other tools than I use?
@@_fluffyy1028write root in Label
what if the button's command is a function that requires me to send a value? I can't use the bracket cus the function will just start. How should I do it? Or if u made a video about it can u link it to me pls
use lambdas...yeah I've done videos on it. command=lambda: function_name(pass stuff)
Hello sir, I am facing a small issue while implementing the code. I have created the click button, but when I click, the command message is printing in my terminal and not inside Tkinker window. Can you please help me which this issue.
rewatch the video and follow the directions exactly. There's no way what you're saying could possibly happen unless you radically changed the code from the video.
at 6:18 when you click the button it adds to the previous line, how can I make it replace it instead?
and great teaching, thanks ^^
You can update anything with .config()
I am create a flutter app using my python code, so a simple app with a button that will open the python code. can you help?
No, I don't have any videos like that
Love your videos! Any idea why pady doesn't work for me? It just puts space between the button and the border of the window on the y axis (padx resizes the button) and not resizing it on the y axis. Thanks!
that's what pady does..puts space on the y axis.
@@Codemycom Yeh but it doesn't change the size of it, like it does for you in the video. In the video it kinda changes the heigh of it, makes it "tall", mine just puts space between the edge of the window and the edge of the button but retains the dimension of the button, the area where i can press it. It's not a big deal, but I thought it was kinda strange, maybe i'm doing something wrong on my end though.
@@immortalkarin Not really...continue watching the videos in the playlist. Learn more of the basics of tkinter and it'll all become clear.
whats the difference between tkinter old version and new from 2021.?. and if it works only with print("that text") after def..
@@kovacsjony4606 I don't know what you mean by old version and new version. There aren't changes.
I imagine the function call parentheses are left off because the statement command already denotes a function. Weird little quirk.
Hello, the button works nicely but i'm facing a problem : I made it so when you click the button it makes you select a file and then it opens it. What i want is also the filePath to be stocked inside a global variable, but whenever I create a variable in the myClick function, I'm unable to reuse it outside of that function, any solution to that problem?
make it global inside that function, define it globally there
you've a great video thanks for that, but i have one qs, what about if that function have arguments how can I do that ?
use lambdas... command=lambda: function(arguments)
@@Codemycom ohh thank you i've tried that and it works.
But the thing is that idk why? Can you refer to some explanation please
@@mohamedlazybob577 That's just how tkinter does it.
@@Codemycom hah thanks for your help
@@mohamedlazybob577 sure thing
how to pass parameters to the function which will execute after button click?
use a lambda
YO!!! Walter White is doing some coding.
lol
How can I create multiple buttons & assign them different commands??
What basically is my problem that -
I have a list wherein I have the text to be displayed on the buttons, & I want them to be displayed... And on clicking a particular button that button gets removed from the display...
Please provide me a solution to this 🙏
keep watching the videos in the playlist.
How can we put picture in our button?
Is that possible? 😅
Yes. I have videos on that in the playlist
Why does 'my_click' work differently than 'my_click()'?
can you please provide the link of ide that you are using
It's just the free sublime text sublimetext.com and the free git bash terminal git-scm.com/downloads
My button works , even though I forgot to add the root to it , can you explain why? I really don't understand what's happening.
No clue
share your code with us.
in dutch we say y as the same as we say an egg, ei. So the joke is, if you smash an egg to a wall, the egg white and yolk will flow down. So thats the trick how i always get it xd. if you dont get it, search for the translation how we say y and egg.
ha!
Is it possible to have oval pentagon buttons using tkinter python?
Yes, but you have to hack an image to click like a button...
@@Codemycom thnk u so much for info..
Do you have any video or examples .
Please sharee na
@@Codemycom i also edit the text on the pentagon button like prev , next text