Radio Buttons with TKinter - Python Tkinter GUI Tutorial #12

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 พ.ย. 2024

ความคิดเห็น • 165

  • @Codemycom
    @Codemycom  4 ปีที่แล้ว

    ▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My TH-cam 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 ปีที่แล้ว +13

    It's a teacher's day in India today. Happy teacher's day John! You have helped me here a lot. Great work.

  • @michaelduckworth3396
    @michaelduckworth3396 4 ปีที่แล้ว +4

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

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      Glad you find them useful!

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

  • @zogoloov4313
    @zogoloov4313 5 ปีที่แล้ว +13

    you are amazing sir print('THANKS')

  • @nassimak2827
    @nassimak2827 3 ปีที่แล้ว +1

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

  • @adihetvi
    @adihetvi 3 ปีที่แล้ว +5

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

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว +2

      Glad you like them!

  • @kelceyfirth
    @kelceyfirth 3 ปีที่แล้ว +2

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

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว +1

      print("Thanks!")

  • @girishjv1078
    @girishjv1078 4 ปีที่แล้ว +7

    Print("thank u")

  • @ycanycan3065
    @ycanycan3065 2 ปีที่แล้ว +1

    Cok tesekkur ederim,emegine yureginize saglik.

  • @GeorgAubele
    @GeorgAubele ปีที่แล้ว

    Thanks! Finally I understand that logic!

    • @Codemycom
      @Codemycom  ปีที่แล้ว

      Happy to hear it!

  • @stevechoatie249
    @stevechoatie249 15 วันที่ผ่านมา

    One question about the toppings list. You obviously capitalized Toppings for a reason, I just wondered why?

  • @ttd972
    @ttd972 4 ปีที่แล้ว +2

    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!

  • @victorga74
    @victorga74 ปีที่แล้ว

    Thanks for sharing Sir

  • @meow-hm7ni
    @meow-hm7ni 4 ปีที่แล้ว +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

  • @uskumru3106
    @uskumru3106 2 ปีที่แล้ว

    Is possible to add multiple choices

  • @dipankarpanda8414
    @dipankarpanda8414 3 ปีที่แล้ว

    Superliked, Thanks.

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      Glad you liked it!

  • @Harish-ou4dy
    @Harish-ou4dy 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      look into the .destroy() function.

  • @mujtabashabbir3171
    @mujtabashabbir3171 3 ปีที่แล้ว

    Amazing waiting

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      waiting for what?

  • @dubhe27
    @dubhe27 5 ปีที่แล้ว +2

    awesome, thanks!

  • @parsabahrambeik4381
    @parsabahrambeik4381 4 ปีที่แล้ว

    Hi, thank you very much for your video.

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      Thank you too

  • @advays9815
    @advays9815 4 ปีที่แล้ว +1

    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?

  • @sarthaksrivastava6282
    @sarthaksrivastava6282 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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.

  • @antukhan5592
    @antukhan5592 4 ปีที่แล้ว +1

    do u have any other tutorial in youtube ?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      Yes, I have hundreds: th-cam.com/users/Codemycom

  • @mahdivatankhah5425
    @mahdivatankhah5425 2 ปีที่แล้ว

    very good

  • @GurpreetSingh-td4es
    @GurpreetSingh-td4es 4 ปีที่แล้ว

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

  • @letsarray5712
    @letsarray5712 3 ปีที่แล้ว

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

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      Because that’s how it works.

  • @smartconjurers2509
    @smartconjurers2509 5 ปีที่แล้ว

    Nice video sir....

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

  • @uvrays045
    @uvrays045 4 ปีที่แล้ว +1

    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?

  • @mdzohaib7368
    @mdzohaib7368 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      You can usually .config things to change them.

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

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

  • @bassusdandoti3073
    @bassusdandoti3073 2 ปีที่แล้ว

    good

  • @russiansouls7348
    @russiansouls7348 4 ปีที่แล้ว

    Can you create if statements using Radiobuttons

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

  • @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 ปีที่แล้ว +2

      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!

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

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

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

  • @Louis-zd2lw
    @Louis-zd2lw 3 ปีที่แล้ว +1

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

  • @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 ปีที่แล้ว +1

      button_name.config(text=whatever)

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

  • @eddywilliams4465
    @eddywilliams4465 4 ปีที่แล้ว +5

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

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +10

      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 ปีที่แล้ว +1

      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

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

  • @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 ปีที่แล้ว +1

      You didn't set them...rewatch the video.

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

  • @issamkessira825
    @issamkessira825 2 ปีที่แล้ว

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

  • @pro_fessor.
    @pro_fessor. ปีที่แล้ว

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

    • @Codemycom
      @Codemycom  ปีที่แล้ว +1

      should probably be root.mainloop()

  • @hansquillrainford6583
    @hansquillrainford6583 2 ปีที่แล้ว +1

    I like you, can you reply me!!!

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว +2

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

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

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

  • @subhasiz
    @subhasiz 4 ปีที่แล้ว

    Sir , I'm getting
    AttributeError: 'NoneType' object has no attribute 'get'

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

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

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

  • @durgeshchandrapatel5943
    @durgeshchandrapatel5943 4 ปีที่แล้ว

    Can you please review my code.?

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว

      Sorry I don't do that

  • @rudraanshpatel553
    @rudraanshpatel553 4 ปีที่แล้ว

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

  • @furive
    @furive 4 ปีที่แล้ว

    Some error about command=Lambda:

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +1

      lambda should be lowercase

  • @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 ปีที่แล้ว +1

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

  • @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 ปีที่แล้ว +1

      @@shubhankarpanda9687 Check my playlist...I have videos on destroy.

    • @shubhankarpanda9687
      @shubhankarpanda9687 3 ปีที่แล้ว

      @@Codemycom ok sir thank you

  • @bxstiii
    @bxstiii 4 ปีที่แล้ว

    Can I Copy this code?? Please send the Code

    • @Codemycom
      @Codemycom  4 ปีที่แล้ว +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

  • @borgyoh
    @borgyoh 5 ปีที่แล้ว

    Second

  • @raz865
    @raz865 5 ปีที่แล้ว +1

    First lol

  • @ELlady69
    @ELlady69 4 ปีที่แล้ว

    to long