Learn Python tkinter GUI radiobuttons easy 🔘

preview_player
Показать описание
Python GUI Tkinter radiobuttons tutorial for beginners

#Python #GUI #Tkinter #radiobuttons #tutorial #beginners

Coding boot camps hate him! See how he can teach you to code with this one simple trick...

Bro Code is the self-proclaimed #1 tutorial series on coding in the known universe.
Рекомендации по теме
Комментарии
Автор

# radio button = similar to checkbox, but you can only select one from a group
from tkinter import *

food = ["pizza", "hamburger", "hotdog"]

def order():
if(x.get()==0):
print("You ordered pizza!")
elif(x.get()==1):
print("You ordered a hamburger!")
elif(x.get()==2):
print("You ordered a hotdog!")
else:
print("huh?")

window = Tk()

pizzaImage = PhotoImage(file='pizza.png')
hamburgerImage =
hotdogImage =
foodImages = [pizzaImage, hamburgerImage, hotdogImage]

x = IntVar()

for index in range(len(food)):
radiobutton = Radiobutton(window,
text=food[index], #adds text to radio buttons
variable=x, #groups radiobuttons together if they share the same variable
value=index, #assigns each radiobutton a different value
padx = 25, #adds padding on x-axis
font=("Impact", 50),
image = foodImages[index], #adds image to radiobutton
compound = 'left', #adds image & text (left-side)
#indicatoron=0, #eliminate circle indicators
#width = 375, #sets width of radio buttons
command=order #set command of radiobutton to function
)
radiobutton.pack(anchor=W)
window.mainloop()

BroCodez
Автор

Hello Bro.. I always see your tutoriarls!!

lucyledezma
Автор

Keep it up love ur great why is ur channel so under ratted never mind i believe u will come in other people recommendations

noisyguest
Автор

A simpler way to write his order function is:
def order():
order = ["You bought the pizza!", "You bought the hamburger!", "You bought the hotdog!"]
print(order[x.get()])

arpanshah
Автор

U should post a link of those images too, pretty cool therse ones

pedroluiz
Автор

Thank you sometimes i wonder how many programming languages u know u should make ur own from Lex

noisyguest
Автор

for me, even width 75 is very large. like 4-5 times more then in example. My screen is 2560x1440.

thePavuk
Автор

Thanks this tutorial was really helpful

Blazer
Автор

In python 3.10 the indicatoron=0 is fine but the compiler expected it to be a boolean, in this case, it is False (Sorry if my English is bad)

haurvatat
Автор

I used f-string for the order function. It's even simplier and all in one line of code.
def order():
print(f"You ordered {food[x.get()]}!")

artury
Автор

thank you very much, you are the best

uuhju
Автор

why can I not find a png image that works?

activechaos
Автор

Hey guys I know this is a comment on a 3-year old post but just want some help. I wrote all the code he used, then I wanted to change the background of the radio button to be blue, so I wrote "bg="blue"" after the width and before the command in the radio button variable. For some reason when I run the code only the hamburger and hot dog changes background to blue and the pizza's background stays as white. I asked ChatGPT 4.0 what could be the issue and they don't have a concrete answer.

Are there any coding connoisseurs that might be able to identify my issue?

haydenmcelmon
Автор

So is there a reason why "im looking i just dont know if its cause obscure.. that when i use .place and coordinates that i am only getting the last Item in the list appearing and thus only hhave 1 radio button? apposed to how pack automatically works with the full list and for:loop ?

maxxinev.pennelope
Автор

Hi, just a quick question!
When I follow the tutorial, I notice that the default selection is the first one.
Is there anyway to deselect that?
Thanks

bbong
Автор

What is the difference between padx and width? I didn"t get it Bro.

minpyaesoesan
Автор

every time i add images its gets all messed up!

hamzazad
Автор

I ordered pizza but never comes????
Bro you are best...

MrEdoben
Автор

I tried creating the image in the for loop because I needed to resize it I added it to a single variable called photo and added the image to the image argument: image=photo, . When I did it messed up the program so that only the last image (the hotdog) showed up . Does it just point to the image in the array you've created rather than copying the image to the radio button? I'll try deleting the array after the for loop and see what happens.

marknunes
join shbcf.ru