Python Forum
[Tkinter] Python - Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Python - Tkinter
#10
Hello guys. I have a small problem with my app(It's not big ,just for experience).
As you can see in the first photo ,when I start my program ,all radiobuttons has a gray color inside(Its not selected),but it has no the default white color I want.When I select a choice,it's white(ok) .So,how can I fix this problem?
Also, as you can see in the 2nd photo when (for example) choose "orange juice" (a big word) and then I choose "Meat" (small word) ,the printing of the word is not obvious. How can I fix this problem?

1st photo
2nd photo

Code:
from tkinter import *

root = Tk()
root.title("Super Market")
root.geometry("1500x1300")

food = [
        ("Rice" , 0.99) ,                       # value for radio_button -> 1
        ("Spaghetti" , 0.95) ,                  # value for radio_button -> 2
        ("Ice cream" , 3.44) ,                  # value for radio_button -> 3
        ("Pizza" , 7.50) ,                      # value for radio_button -> 4
        ("Cheese" , 2.10) ,                     # value for radio_button -> 5
        ("Cheddar" , 0.45) ,                    # value for radio_button -> 6
        ("Cherry" , 0.88) ,                     # value for radio_button -> 7
        ("Banana" , 0.40) ,                     # value for radio_button -> 8
        ("Apple" , 0.67) ,                      # value for radio_button -> 9
        ("Meat" , 7.28) ,                       # value for radio_button -> 10
        ("Fish" , 9.72) ,                       # value for radio_button -> 11
        ("Orange" , 0.62) ,                     # value for radio_button -> 12
        ("Orange juice" , 2.10) ,               # value for radio_button -> 13
        ("Chocolate" , 0.99) ,                  # value for radio_button -> 14
        ("Bread" , 0.55)                        # value for radio_button -> 15
       ]


food_name_var = StringVar()

frame = LabelFrame(root , relief = SUNKEN , bd = 1)
frame.grid(row = 0 , column = 0 , sticky = W)

r = 0
for food_name , food_price in food:
        Radiobutton(frame , text = food_name , variable = food_name_var , value = r+1 , padx = 10 , pady = 5).grid(row = r , column = 0 , sticky = W)
        label_price = LabelFrame(root , relief = SUNKEN , bd = 1 , text = "Price")
        label_price.grid(row = r , column = 1 , sticky = W)
        r += 1
        

def select_food(food_name):
        label_print_food = Label(root , text = food_name)
        label_print_food.grid(row = 0 , column = 4)
        

button = Button(root , text = "Basket" , command = lambda: select_food(food[ int(food_name_var.get() ) - 1][0]) )
button.grid(row = 0 , column = 3)


root.mainloop()
Thanks in advance Smile
Reply


Messages In This Thread
Python - Tkinter - by Ditrate40 - Dec-06-2018, 05:53 PM
RE: Python - Tkinter - by Larz60+ - Dec-06-2018, 08:26 PM
RE: Python - Tkinter - by Ditrate40 - Dec-07-2018, 01:36 PM
RE: Python - Tkinter - by woooee - Dec-07-2018, 04:38 PM
RE: Python - Tkinter - by nilamo - Dec-07-2018, 04:44 PM
RE: Python - Tkinter - by Ditrate40 - Dec-08-2018, 12:35 PM
RE: Python - Tkinter - by nilamo - Dec-09-2018, 05:27 AM
RE: Python - Tkinter - by Ditrate40 - Dec-09-2018, 11:40 AM
RE: Python - Tkinter - by Ditrate40 - Dec-09-2018, 04:39 PM
RE: Python - Tkinter - by Nick_tkinter - Feb-12-2021, 01:48 PM
RE: Python - Tkinter - by Nick_tkinter - Feb-12-2021, 01:53 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020