Radio Buttons with TKinter - Python Tkinter GUI Tutorial #12

  Рет қаралды 126,736

Codemy.com

Codemy.com

Күн бұрын

Пікірлер: 164
@Codemycom
@Codemycom 4 жыл бұрын
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My KZbin 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
@shivamkalra4295
@shivamkalra4295 4 жыл бұрын
It's a teacher's day in India today. Happy teacher's day John! You have helped me here a lot. Great work.
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@michaelduckworth3396
@michaelduckworth3396 3 жыл бұрын
I love these videos. I refer back to these everyday to try and build my stuff
@Codemycom
@Codemycom 3 жыл бұрын
Glad you find them useful!
@zogoloov4313
@zogoloov4313 5 жыл бұрын
you are amazing sir print('THANKS')
@Codemycom
@Codemycom 5 жыл бұрын
Thanks!!
@adihetvi
@adihetvi 3 жыл бұрын
Your videos are amazing...exactly what i want print("Thank you")
@Codemycom
@Codemycom 3 жыл бұрын
Glad you like them!
@KadeMccarroll
@KadeMccarroll Жыл бұрын
Thank you, I am learning tkinter right now and I wanted to let you know I am having trouble learning some of it, and you are good at explaining.
@Codemycom
@Codemycom Жыл бұрын
Happy to hear it!
@nassimak2827
@nassimak2827 3 жыл бұрын
U make me love Python more and more ! Tkx for ur effort !
@kelceyfirth
@kelceyfirth 3 жыл бұрын
if name==“John”: print(“You are awesome and a great teacher!”)
@Codemycom
@Codemycom 3 жыл бұрын
print("Thanks!")
@ycanycan3065
@ycanycan3065 2 жыл бұрын
Cok tesekkur ederim,emegine yureginize saglik.
@GeorgAubele
@GeorgAubele Жыл бұрын
Thanks! Finally I understand that logic!
@Codemycom
@Codemycom Жыл бұрын
Happy to hear it!
@girishjv1078
@girishjv1078 4 жыл бұрын
Print("thank u")
@Codemycom
@Codemycom 4 жыл бұрын
Sure thing
@victorga74
@victorga74 Жыл бұрын
Thanks for sharing Sir
@Codemycom
@Codemycom Жыл бұрын
Welcome
@ttd972
@ttd972 4 жыл бұрын
In this case it would be simpler to create a single label, with the attribute textvariable=pizza. Then it will always show which option is selected
@Codemycom
@Codemycom 4 жыл бұрын
lot's of ways to do it
@ttd972
@ttd972 4 жыл бұрын
@@Codemycom yep, thanks for the great content!
@parsabahrambeik4381
@parsabahrambeik4381 4 жыл бұрын
Hi, thank you very much for your video.
@Codemycom
@Codemycom 4 жыл бұрын
Thank you too
@dipankarpanda8414
@dipankarpanda8414 3 жыл бұрын
Superliked, Thanks.
@Codemycom
@Codemycom 3 жыл бұрын
Glad you liked it!
@mujtabashabbir3171
@mujtabashabbir3171 3 жыл бұрын
Amazing waiting
@Codemycom
@Codemycom 3 жыл бұрын
waiting for what?
@dubhe27
@dubhe27 5 жыл бұрын
awesome, thanks!
@GurpreetSingh-td4es
@GurpreetSingh-td4es 4 жыл бұрын
you just awsome sir make me code a lot better :-}
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@mahdivatankhah5425
@mahdivatankhah5425 2 жыл бұрын
very good
@Codemycom
@Codemycom 2 жыл бұрын
Thanks!
@uskumru3106
@uskumru3106 2 жыл бұрын
Is possible to add multiple choices
@meow-hm7ni
@meow-hm7ni 4 жыл бұрын
lambda looks like a capital L lol. got error on my code. good tutorial though.
@Codemycom
@Codemycom 4 жыл бұрын
yeah, that drives me crazy...I don't know why sublime does that
@smartconjurers2509
@smartconjurers2509 5 жыл бұрын
Nice video sir....
@Codemycom
@Codemycom 5 жыл бұрын
Thanks!
@sarthaksrivastava6282
@sarthaksrivastava6282 4 жыл бұрын
how can we make the buttons deselect themselves if we click on them again? like I tried making a multi correct MCQ, I assigned different variables to different buttons so one can select multiple buttons but how to deselect if we click on it again??
@Codemycom
@Codemycom 4 жыл бұрын
Like I said, create a function that gets called every time the button is clicked that keeps track of the current state of the button and acts accordingly to deselect itself.
@advays9815
@advays9815 4 жыл бұрын
sir? can we display the options and not have the value that we set be displayed on the screen to the user?
@Codemycom
@Codemycom 4 жыл бұрын
Can't you tell from the video?
@akilamp8470
@akilamp8470 4 жыл бұрын
@@Codemycom I managed to figure it out. Thank you! Also can you tell me how to pass the value you get when you click a radiobutton in a seperate variable?
@letsarray5712
@letsarray5712 3 жыл бұрын
i want ask you, why you use lambda in your command?
@Codemycom
@Codemycom 3 жыл бұрын
Because that’s how it works.
@Harish-ou4dy
@Harish-ou4dy 4 жыл бұрын
I used grid to update the labels containing string, every time label gets updated there are some fragments of text of previous label seen beneath the current one (for ecample if first label was Pepperoni then next was egg), so "P" and "i" of Pepperoni will still be visible when egg is the new updated label.
@Codemycom
@Codemycom 4 жыл бұрын
look into the .destroy() function.
@chinmaykulkarni7835
@chinmaykulkarni7835 4 жыл бұрын
So if I click a radio button it will consider one time entering in function or continuously as long as it is activated?
@durgeshchandrapatel5943
@durgeshchandrapatel5943 4 жыл бұрын
Only at the time when it is toggled like on or off.
@bassusdandoti3073
@bassusdandoti3073 2 жыл бұрын
good
@lawrencetheguywithjustfact4767
@lawrencetheguywithjustfact4767 Жыл бұрын
Please help. I am in a cybersecurity class and I have to make either a checkbutton or radio button and whenever I try it says there’s a Tcl error and means that Tcl wasn’t installed properly, but what is Tcl and how do I install it properly?
@Codemycom
@Codemycom Жыл бұрын
use the tools I use and the code I write and you won't have errors like that
@ssigitas69
@ssigitas69 3 жыл бұрын
Hi. I have stupid question. IntVar, Radiobutton, title, Label, .get on your editor have blue color. I'm using Pycharm, how to change colors for Tkinter commands? Thanks
@Codemycom
@Codemycom 3 жыл бұрын
What could it possibly matter? Don't use pycharm
@mdzohaib7368
@mdzohaib7368 4 жыл бұрын
Sir can u tell me how to remove the current label nd whenever i click on any other radiobutton the label gets overwrite rather than showing its mode in next row?
@mdzohaib7368
@mdzohaib7368 4 жыл бұрын
I think there must be some command like label.rem smthng to remove the current label and replace in same row with other label whenever i click on other radiobutton.
@Codemycom
@Codemycom 4 жыл бұрын
You can usually .config things to change them.
@uvrays045
@uvrays045 4 жыл бұрын
If i click a button, how do i make the screen of the gui clear of ? Can u plz help ?
@infinitespace1982
@infinitespace1982 3 жыл бұрын
Maybe, you could try opening another window with the same name, and delete the original?
@antukhan5592
@antukhan5592 4 жыл бұрын
do u have any other tutorial in youtube ?
@Codemycom
@Codemycom 4 жыл бұрын
Yes, I have hundreds: kzbin.info
@dead1ock284
@dead1ock284 4 жыл бұрын
So i did the same as you with the for loop but i had 7 radio buttons, i even set the value of the radio buttons variable to '1' but every time i run the program, all the buttons are marked but when i click on one button then all of the buttons get unmarked like it needs to be. how do i fix this problem?
@Codemycom
@Codemycom 4 жыл бұрын
There's a problem with your code, but I don't know what.
@dead1ock284
@dead1ock284 4 жыл бұрын
@@Codemycom never mind i managed to figure it out but thanks anyways for replying to my comment :)
@ogspeace
@ogspeace 4 жыл бұрын
is there a difference between root.mainloop() and just calling mainloop() ? i noticed that you used `mainloop()` instead of `root.mainloop()` starting w/ this vid (and onwards). also, do you have a tutorial on implementing tkinter in classes? (oop). thanks.
@Codemycom
@Codemycom 4 жыл бұрын
Videos with classes will be coming soon :-)
@dong8912
@dong8912 4 жыл бұрын
Great Video. I have one question though, When I tried to create radio buttons within a function, I can't seem to get the IntVar variable to change and it always stays as the default value, regardless of which radio button is selected. Is there a way to fix this?
@Codemycom
@Codemycom 4 жыл бұрын
I think there must just be a typo in your code
@dong8912
@dong8912 4 жыл бұрын
@@Codemycom Nope, no typos. My script includes 6 radio buttons in total, 3 of which are outside a function and the other 3 in a function - the function is called by clicking a button, which opens up a new window that contains the other 3 radio buttons. All radio button lines look exactly the same, with only the values and texts being different. I even tried using global variables but that still didn't work. I think it may be helpful to mention that i am also using IDLE to run my scripts
@dong8912
@dong8912 4 жыл бұрын
So I managed to fix this issue, and also a bunch of other issues relating to some widgets not working in a function-generated window. Essentially, The very first window opened in the script uses the command: root = Tk(). since I'm creating more than one window concurrently, instead of using: window = Tk() to create that window, I instead use: window = Toplevel(). Apparently tkinter is designed such that only one Tk() window can be opened at a time, and to open multiple windows, I need to use Toplevel(). But yeah this fixes the issue of the radio buttons not working. Also I just realised you already made a video covering this and that I totally forgot.
@Codemycom
@Codemycom 4 жыл бұрын
@@dong8912 Glad you got it sorted out!
@dong8912
@dong8912 4 жыл бұрын
@Codemy.com Thanks!
@kunalsah4895
@kunalsah4895 4 жыл бұрын
hey, can we change color of dot in the radio button
@Codemycom
@Codemycom 4 жыл бұрын
When defining the radio button, try setting the selectcolor="red" or whatever color
@russiansouls7348
@russiansouls7348 4 жыл бұрын
Can you create if statements using Radiobuttons
@Codemycom
@Codemycom 4 жыл бұрын
Of course
@rudraanshpatel553
@rudraanshpatel553 4 жыл бұрын
How can we bind radio buttons such that pressing certain keys selects those radio buttons, please make a video on this?
@Codemycom
@Codemycom 4 жыл бұрын
I have videos in the playlist on bindings
@durgeshchandrapatel5943
@durgeshchandrapatel5943 4 жыл бұрын
@@Codemycom You don't have any of them to bind radio buttons.
@durgeshchandrapatel5943
@durgeshchandrapatel5943 4 жыл бұрын
@@Codemycom I want to navigate between options of a quiz, like if I click a , a gets selected...
@yukidango6730
@yukidango6730 4 жыл бұрын
How can I get the text from the selected radiobutton and put it inside a normal variable??
@Codemycom
@Codemycom 4 жыл бұрын
Don't we discuss that? If not, check the playlist.
@nicovdt7074
@nicovdt7074 2 жыл бұрын
I cant seem to get Lambda working is there a video where you explain it more?
@Codemycom
@Codemycom 2 жыл бұрын
you're mis-spelling lambda. It needs to have a lowercase l not L
@eddywilliams4465
@eddywilliams4465 4 жыл бұрын
"which is insanely cheap " tone makes me laugh🤣🤣🤣🤣🤣🤣🤣🤣
@Codemycom
@Codemycom 4 жыл бұрын
Ah, but did it make you buy? LMAO
@tszabon
@tszabon 4 жыл бұрын
hi, how can I pass the value to variable when "Click Me" button is pressed and close checkbox window automatically?
@Codemycom
@Codemycom 4 жыл бұрын
I explain all of that in the videos in this playlist...
@richardbenny7891
@richardbenny7891 3 жыл бұрын
my radiobutton does not deselect after choosing another one any solutions for the same??
@Codemycom
@Codemycom 3 жыл бұрын
You just have a typo somewhere
@Louis-zd2lw
@Louis-zd2lw 3 жыл бұрын
How to unclick ? and when it's clicked print 1 else 0
@fernandohood5542
@fernandohood5542 4 жыл бұрын
How do you use the place() method with the radio button? The object is being created but not assigned to anything?
@Codemycom
@Codemycom 4 жыл бұрын
I never use place, but you use it with the radio button the same way you use it with every other widget.
@Aleinux
@Aleinux 3 жыл бұрын
Every time you click on the button, you get a new line whit the value of the radio button. If I want refresh the line and no insert a new line each time. How can I do?
@Codemycom
@Codemycom 3 жыл бұрын
button_name.config(text=whatever)
@hansquillrainford6583
@hansquillrainford6583 2 жыл бұрын
I like you, can you reply me!!!
@leothomas1113
@leothomas1113 2 жыл бұрын
gender=StringVar() Radiobutton(root, text='Male', variable=gender, value='Male').place(x=150, y=220) Radiobutton(root, text='Female', variable=gender, value='Female').place(x=220, y=220) Both the radio buttons selected by default for me. How to resolve that ?
@Codemycom
@Codemycom 2 жыл бұрын
You didn't set them...rewatch the video.
@issamkessira825
@issamkessira825 2 жыл бұрын
can any one please tell me how to disable the other radiobuttons once someone chooses onion?
@sushmachandran2179
@sushmachandran2179 4 жыл бұрын
my code doesn't like the "command =Lambda:" even though I have imported from _ast Lambda from _ast import Lambda from tkinter import * from PIL import ImageTk,Image root = Tk() r = IntVar() #r.set("2") def clicked(value): myLabel = Label(root, text=value) myLabel.pack() Radiobutton(root, text="Option 1", variable=r, value=1, command=Lambda: clicked(r.get())).pack() Radiobutton(root, text="Option 2", variable=r, value=2).pack() mainloop() It claims that Lambda is an invalid syntax.
@Codemycom
@Codemycom 4 жыл бұрын
Don't import Lambda. Your code needs lowercase l in lambda, not uppercase
@sushmachandran2179
@sushmachandran2179 4 жыл бұрын
@@Codemycom That fixed it. Thanks a ton!
@Codemycom
@Codemycom 4 жыл бұрын
@@sushmachandran2179 Sure thing
@PraptyChanda
@PraptyChanda 4 жыл бұрын
I have written the following code. I haven't set the value of r but still, in the beginning all the options are shown as selected. r = StringVar() Radiobutton(frame,text="option 1",variable=r,value="1").pack() Radiobutton(frame,text="option 2",variable=r,value="2").pack() Radiobutton(frame,text="option 3",variable=r,value="3").pack() I followed your code. In your output, it doesn't show selected if its not set. But I don't understand why in mine all the options are pre selected. Is there a way to remove those?
@Codemycom
@Codemycom 4 жыл бұрын
You need to set one.
@PraptyChanda
@PraptyChanda 4 жыл бұрын
@@Codemycom okay will try that. Thank you!
@pradnyeshprabhu4458
@pradnyeshprabhu4458 4 жыл бұрын
My radio buttons get selected even without clicking on it. Just move near to radio button and it gets selected moreover both get selected at a time i.e. one doesn't get unselected when other one is selecetd. Help me. Below is my code: from tkinter import * def script(): return r = IntVar root = Tk() root.title('Renaming Parts') textbox = Entry(root, width=50) textbox.grid(row=0, column=0, columnspan=4) Radiobutton(root, text='WIRE', variable=r, value=1).grid(row=2, column=0, columnspan=2) Radiobutton(root, text='COMPO', variable=r, value=2).grid(row=2, column=3, columnspan=2) Enter = Button(root, text='Enter', width=25, command=script).grid(row=3, column=0, columnspan=2) Exit = Button(root, text='Exit', width=25, command=root.destroy).grid(row=3, column=3, columnspan=2) root.mainloop()
@Codemycom
@Codemycom 4 жыл бұрын
Two things...your r=IntVar needs to be r = IntVar() you fogot the parenthesis. Next, make the radiobutton variable global. So above the RadioButton code, go: global r r = IntVar()
@pro_fessor.
@pro_fessor. Жыл бұрын
Why using mainloop() Instead of root.mainloop() In las line
@Codemycom
@Codemycom Жыл бұрын
should probably be root.mainloop()
@Harish-ou4dy
@Harish-ou4dy 4 жыл бұрын
strangely enough, text=r.get() doesnt work when using r as a StringVar(). Even after setting r.set="sample string"... Nothing shows up, when tried to check by print(r.get()), its a blank string.
@Codemycom
@Codemycom 4 жыл бұрын
r.set() not r.set
@Harish-ou4dy
@Harish-ou4dy 4 жыл бұрын
@@Codemycom BullsEye!! thanks ..
@Codemycom
@Codemycom 4 жыл бұрын
@@Harish-ou4dy good :-)
@shekhsaiful1054
@shekhsaiful1054 4 жыл бұрын
I got an error it says list object doesn't have get attribute .. how to fix this
@Codemycom
@Codemycom 4 жыл бұрын
check your code for typos
@sudeepsanthosh8819
@sudeepsanthosh8819 4 жыл бұрын
sir I am facing a problem for me when I open my window all the the radio buttons are already pre selected plss help
@Codemycom
@Codemycom 4 жыл бұрын
did you not change something in each of the radio button code?
@sudeepsanthosh8819
@sudeepsanthosh8819 4 жыл бұрын
@@Codemycom no
@yukidango6730
@yukidango6730 4 жыл бұрын
I tried doing the StrVar() but it says it is an undefined variable
@Codemycom
@Codemycom 4 жыл бұрын
Check your code for typos
@yukidango6730
@yukidango6730 4 жыл бұрын
@@Codemycom I just corrected it, it isn't StrVar() it is StringVar() xD
@Codemycom
@Codemycom 4 жыл бұрын
@@yukidango6730 ;-)
@just_all_in
@just_all_in 4 жыл бұрын
my button does not deselect when I click the other
@Codemycom
@Codemycom 4 жыл бұрын
Check your code for typos
@just_all_in
@just_all_in 4 жыл бұрын
@@Codemycom my code is from tkinter import * root = Tk() root.title('EX001') r = IntVar Radiobutton(root, text='op01',variable=r,value=1).pack() Radiobutton(root, text='op02',variable=r,value=2).pack() mainloop()
@subhasiz
@subhasiz 4 жыл бұрын
Sir , I'm getting AttributeError: 'NoneType' object has no attribute 'get'
@Codemycom
@Codemycom 4 жыл бұрын
you need to do .get() not .get and make sure not to .pack() on the same line
@subhasiz
@subhasiz 4 жыл бұрын
Thank you sir, it worked
@Codemycom
@Codemycom 4 жыл бұрын
@@subhasiz Great!
@alitalhaoylek2413
@alitalhaoylek2413 4 жыл бұрын
Why we can't .pack() at the same line?
@Codemycom
@Codemycom 4 жыл бұрын
Because it confuses tkinter if there's a function to call.
@alitalhaoylek2413
@alitalhaoylek2413 4 жыл бұрын
@@Codemycom thanks
@Codemycom
@Codemycom 4 жыл бұрын
@@alitalhaoylek2413 sure thing
@Skyvastern
@Skyvastern 5 жыл бұрын
lol the name of your PC is flatplanet? Didn't know that you were a flat earther 😁
@Codemycom
@Codemycom 5 жыл бұрын
I'm not, I just find it hilarious that some people do so I named my computer that lol
@Skyvastern
@Skyvastern 5 жыл бұрын
@@Codemycom yeah I got that feeling that it was named as a joke xD
@rudraanshpatel553
@rudraanshpatel553 4 жыл бұрын
Seems like you have crammed your advertisement. '''Which is insanely cheap xD'''
@Codemycom
@Codemycom 4 жыл бұрын
huh?
@borgyoh
@borgyoh 5 жыл бұрын
Second
@Codemycom
@Codemycom 5 жыл бұрын
ha!
@durgeshchandrapatel5943
@durgeshchandrapatel5943 4 жыл бұрын
Can you please review my code.?
@Codemycom
@Codemycom 4 жыл бұрын
Sorry I don't do that
@furive
@furive 4 жыл бұрын
Some error about command=Lambda:
@Codemycom
@Codemycom 4 жыл бұрын
lambda should be lowercase
@shubhankarpanda9687
@shubhankarpanda9687 3 жыл бұрын
how to destroy radio buttons?
@Codemycom
@Codemycom 3 жыл бұрын
.destroy()
@shubhankarpanda9687
@shubhankarpanda9687 3 жыл бұрын
@@Codemycom it is not working in for loops as well as in single creation
@shubhankarpanda9687
@shubhankarpanda9687 3 жыл бұрын
@@Codemycom can you please refer some documentation on this
@Codemycom
@Codemycom 3 жыл бұрын
@@shubhankarpanda9687 Check my playlist...I have videos on destroy.
@shubhankarpanda9687
@shubhankarpanda9687 3 жыл бұрын
@@Codemycom ok sir thank you
@raz865
@raz865 5 жыл бұрын
First lol
@Codemycom
@Codemycom 5 жыл бұрын
Ha!
@bxstiii
@bxstiii 4 жыл бұрын
Can I Copy this code?? Please send the Code
@Codemycom
@Codemycom 4 жыл бұрын
Don't be lazy.
@bxstiii
@bxstiii 4 жыл бұрын
@@Codemycom have now written to me the code and it has helped me can you be reached on discord ??
@Codemycom
@Codemycom 4 жыл бұрын
@@bxstiii No, sorry
@ELlady69
@ELlady69 4 жыл бұрын
to long
@Codemycom
@Codemycom 4 жыл бұрын
incorrect
Message Boxes with TKinter - Python Tkinter GUI Tutorial #13
11:49
Radio Buttons in CustomTkinter - Tkinter CustomTkinter 7
18:10
Tkinter․com
Рет қаралды 8 М.
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 38 МЛН
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 21 МЛН
Python GUI Development With PySimpleGUI
15:15
Real Python
Рет қаралды 1 МЛН
Learn Python tkinter GUI radiobuttons easy 🔘
12:22
Bro Code
Рет қаралды 24 М.
Open Files Dialog Box - Python Tkinter GUI Tutorial #15
12:34
Codemy.com
Рет қаралды 193 М.
Create Stunning Python GUIs in 10 Minutes With Drag & Drop
11:38
Coding Is Fun
Рет қаралды 87 М.
Convert GUI App to Real Program -  Python to exe to setup wizard
23:27
Python Simplified
Рет қаралды 541 М.
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 38 МЛН