Radio Buttons with TKinter - Python Tkinter GUI Tutorial #12

How to use Radio Buttons with TKinter and Python. In this video I'll show you how to use Radio Buttons with your python tkinter program.
In this series I'll show you how to create graphical user interfaces for Python with Tkinter.
✅ 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 KZread Channel:
bit.ly/2IGzvOR
▶️ Learn to Code at Codemy.com
Take $22 off with coupon code: youtube

Пікірлер: 164

  • @Codemycom
    @Codemycom4 жыл бұрын

    ▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My KZread 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
    @shivamkalra42953 жыл бұрын

    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

    3 жыл бұрын

    Thanks!

  • @michaelduckworth3396
    @michaelduckworth33963 жыл бұрын

    I love these videos. I refer back to these everyday to try and build my stuff

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Glad you find them useful!

  • @nassimak2827
    @nassimak28273 жыл бұрын

    U make me love Python more and more ! Tkx for ur effort !

  • @adihetvi
    @adihetvi3 жыл бұрын

    Your videos are amazing...exactly what i want print("Thank you")

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Glad you like them!

  • @ycanycan3065
    @ycanycan3065 Жыл бұрын

    Cok tesekkur ederim,emegine yureginize saglik.

  • @user-fd4sk8ev4d
    @user-fd4sk8ev4d Жыл бұрын

    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!

  • @dubhe27
    @dubhe275 жыл бұрын

    awesome, thanks!

  • @zogoloov4313
    @zogoloov43134 жыл бұрын

    you are amazing sir print('THANKS')

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Thanks!!

  • @GeorgAubele
    @GeorgAubele Жыл бұрын

    Thanks! Finally I understand that logic!

  • @Codemycom

    @Codemycom

    Жыл бұрын

    Happy to hear it!

  • @parsabahrambeik4381
    @parsabahrambeik43813 жыл бұрын

    Hi, thank you very much for your video.

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Thank you too

  • @victorga74
    @victorga74 Жыл бұрын

    Thanks for sharing Sir

  • @Codemycom

    @Codemycom

    Жыл бұрын

    Welcome

  • @mujtabashabbir3171
    @mujtabashabbir31712 жыл бұрын

    Amazing waiting

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    waiting for what?

  • @dipankarpanda8414
    @dipankarpanda84142 жыл бұрын

    Superliked, Thanks.

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Glad you liked it!

  • @kelceyfirth
    @kelceyfirth3 жыл бұрын

    if name==“John”: print(“You are awesome and a great teacher!”)

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    print("Thanks!")

  • @smartconjurers2509
    @smartconjurers25094 жыл бұрын

    Nice video sir....

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Thanks!

  • @GurpreetSingh-td4es
    @GurpreetSingh-td4es4 жыл бұрын

    you just awsome sir make me code a lot better :-}

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Thanks!

  • @mahdivatankhah5425
    @mahdivatankhah54252 жыл бұрын

    very good

  • @Codemycom

    @Codemycom

    2 жыл бұрын

    Thanks!

  • @bassusdandoti3073
    @bassusdandoti30732 жыл бұрын

    good

  • @Harish-ou4dy
    @Harish-ou4dy4 жыл бұрын

    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.

  • @girishjv1078
    @girishjv10783 жыл бұрын

    Print("thank u")

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Sure thing

  • @sarthaksrivastava6282
    @sarthaksrivastava62824 жыл бұрын

    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.

  • @ttd972
    @ttd9723 жыл бұрын

    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

    3 жыл бұрын

    lot's of ways to do it

  • @ttd972

    @ttd972

    3 жыл бұрын

    @@Codemycom yep, thanks for the great content!

  • @uskumru3106
    @uskumru31062 жыл бұрын

    Is possible to add multiple choices

  • @chinmaykulkarni7835
    @chinmaykulkarni78353 жыл бұрын

    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

    3 жыл бұрын

    Only at the time when it is toggled like on or off.

  • @ogspeace
    @ogspeace4 жыл бұрын

    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 :-)

  • @tszabon
    @tszabon4 жыл бұрын

    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...

  • @uvrays045
    @uvrays0454 жыл бұрын

    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?

  • @yukidango6730
    @yukidango67304 жыл бұрын

    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.

  • @advays9815
    @advays98154 жыл бұрын

    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

    3 жыл бұрын

    @@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?

  • @mdzohaib7368
    @mdzohaib73684 жыл бұрын

    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.

  • @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

  • @fernandohood5542
    @fernandohood55424 жыл бұрын

    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.

  • @antukhan5592
    @antukhan55924 жыл бұрын

    do u have any other tutorial in youtube ?

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Yes, I have hundreds: kzread.info

  • @meow-hm7ni
    @meow-hm7ni4 жыл бұрын

    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

  • @dead1ock284
    @dead1ock2844 жыл бұрын

    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 :)

  • @rudraanshpatel553
    @rudraanshpatel5533 жыл бұрын

    How can we bind radio buttons such that pressing certain keys selects those radio buttons, please make a video on this?

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    I have videos in the playlist on bindings

  • @durgeshchandrapatel5943

    @durgeshchandrapatel5943

    3 жыл бұрын

    @@Codemycom You don't have any of them to bind radio buttons.

  • @durgeshchandrapatel5943

    @durgeshchandrapatel5943

    3 жыл бұрын

    @@Codemycom I want to navigate between options of a quiz, like if I click a , a gets selected...

  • @letsarray5712
    @letsarray57123 жыл бұрын

    i want ask you, why you use lambda in your command?

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Because that’s how it works.

  • @ssigitas69
    @ssigitas693 жыл бұрын

    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

  • @issamkessira825
    @issamkessira8252 жыл бұрын

    can any one please tell me how to disable the other radiobuttons once someone chooses onion?

  • @kunalsah4895
    @kunalsah48954 жыл бұрын

    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

  • @dong8912
    @dong89123 жыл бұрын

    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

    3 жыл бұрын

    I think there must just be a typo in your code

  • @dong8912

    @dong8912

    3 жыл бұрын

    @@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

    3 жыл бұрын

    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

    3 жыл бұрын

    @@dong8912 Glad you got it sorted out!

  • @dong8912

    @dong8912

    3 жыл бұрын

    @Codemy.com Thanks!

  • @russiansouls7348
    @russiansouls73484 жыл бұрын

    Can you create if statements using Radiobuttons

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Of course

  • @Aleinux
    @Aleinux2 жыл бұрын

    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

    2 жыл бұрын

    button_name.config(text=whatever)

  • @nicovdt7074
    @nicovdt7074 Жыл бұрын

    I cant seem to get Lambda working is there a video where you explain it more?

  • @Codemycom

    @Codemycom

    Жыл бұрын

    you're mis-spelling lambda. It needs to have a lowercase l not L

  • @Louis-zd2lw
    @Louis-zd2lw3 жыл бұрын

    How to unclick ? and when it's clicked print 1 else 0

  • @richardbenny7891
    @richardbenny78913 жыл бұрын

    my radiobutton does not deselect after choosing another one any solutions for the same??

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    You just have a typo somewhere

  • @Harish-ou4dy
    @Harish-ou4dy4 жыл бұрын

    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 :-)

  • @pradnyeshprabhu4458
    @pradnyeshprabhu44584 жыл бұрын

    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()

  • @shekhsaiful1054
    @shekhsaiful10544 жыл бұрын

    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

  • @eddywilliams4465
    @eddywilliams44654 жыл бұрын

    "which is insanely cheap " tone makes me laugh🤣🤣🤣🤣🤣🤣🤣🤣

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    Ah, but did it make you buy? LMAO

  • @leothomas1113
    @leothomas11132 жыл бұрын

    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.

  • @subhasiz
    @subhasiz4 жыл бұрын

    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!

  • @yukidango6730
    @yukidango67304 жыл бұрын

    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 ;-)

  • @sudeepsanthosh8819
    @sudeepsanthosh88193 жыл бұрын

    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

    3 жыл бұрын

    did you not change something in each of the radio button code?

  • @sudeepsanthosh8819

    @sudeepsanthosh8819

    3 жыл бұрын

    @@Codemycom no

  • @PraptyChanda
    @PraptyChanda4 жыл бұрын

    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!

  • @sushmachandran2179
    @sushmachandran21793 жыл бұрын

    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

    3 жыл бұрын

    Don't import Lambda. Your code needs lowercase l in lambda, not uppercase

  • @sushmachandran2179

    @sushmachandran2179

    3 жыл бұрын

    @@Codemycom That fixed it. Thanks a ton!

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    @@sushmachandran2179 Sure thing

  • @pro_fessor.
    @pro_fessor. Жыл бұрын

    Why using mainloop() Instead of root.mainloop() In las line

  • @Codemycom

    @Codemycom

    Жыл бұрын

    should probably be root.mainloop()

  • @alitalhaoylek2413
    @alitalhaoylek24134 жыл бұрын

    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

  • @just_all_in
    @just_all_in3 жыл бұрын

    my button does not deselect when I click the other

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Check your code for typos

  • @just_all_in

    @just_all_in

    3 жыл бұрын

    @@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()

  • @hansquillrainford6583
    @hansquillrainford65832 жыл бұрын

    I like you, can you reply me!!!

  • @borgyoh
    @borgyoh5 жыл бұрын

    Second

  • @Codemycom

    @Codemycom

    5 жыл бұрын

    ha!

  • @Skyvastern
    @Skyvastern4 жыл бұрын

    lol the name of your PC is flatplanet? Didn't know that you were a flat earther 😁

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    I'm not, I just find it hilarious that some people do so I named my computer that lol

  • @Skyvastern

    @Skyvastern

    4 жыл бұрын

    @@Codemycom yeah I got that feeling that it was named as a joke xD

  • @furive
    @furive4 жыл бұрын

    Some error about command=Lambda:

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    lambda should be lowercase

  • @rudraanshpatel553
    @rudraanshpatel5533 жыл бұрын

    Seems like you have crammed your advertisement. '''Which is insanely cheap xD'''

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    huh?

  • @durgeshchandrapatel5943
    @durgeshchandrapatel59433 жыл бұрын

    Can you please review my code.?

  • @Codemycom

    @Codemycom

    3 жыл бұрын

    Sorry I don't do that

  • @raz865
    @raz8655 жыл бұрын

    First lol

  • @Codemycom

    @Codemycom

    5 жыл бұрын

    Ha!

  • @shubhankarpanda9687
    @shubhankarpanda96873 жыл бұрын

    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

  • @bxstiii
    @bxstiii4 жыл бұрын

    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
    @ELlady694 жыл бұрын

    to long

  • @Codemycom

    @Codemycom

    4 жыл бұрын

    incorrect