Урок №6: Python tkinter Радиокнопки графического интерфейса пользователя

Аватар автора
Уроки программирования на русском языке
Уроки программирования на русском языке # 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 = PhotoImage(file='hamburger.png') hotdogImage = PhotoImage(file='hotdog.png') foodImages = [pizzaImage,hamburgerImage,hotdogImage] x = IntVar() for index in range(len(food)): radiobutton = Radiobutton(window, text=food[index], text to radio buttons variable=x, radiobuttons together if they share the same variable value=index, each radiobutton a different value padx = 25, padding on x-axis font=("Impact",50), image = foodImages[index], image to radiobutton compound = &image & text (left-side) circle indicators = 375, width of radio buttons command=order command of radiobutton to function ) radiobutton.pack(anchor=W) window.mainloop()

0/0


0/0

0/0

0/0