'Problems with my GUI with tkinter using information from a .csv file

I have recently started programming with python and am currently working, for practice purposes, on a program with which a restaurant can take orders. The ‘menu’ is available as a CSV file. My GUI currently looks like this:

https://bilderupload.org/bild/983a84049-gui8860a4e27cbbe4c6343984

The two checkbuttons and entrys under ‘Food’ are the two that works and the two I created individually. The checkbuttons under drinks are created with the content from the csv document. I can tick the checkbuttons but the entry is still greyed out, even if there is a tick in the checkbutton.

You have to tick the dishes you ordered to activate the entry field (if there is no tick in the checkbutton, you cannot enter something in the field).

This works, if I create the checkbutton and entry variables for each dish individually, but not if I want to use the content from the CSV file as variables. Can someone help me or has a better idea to solve my problem?

The .csv file looks like this:

https://bilderupload.org/bild/b8c286400-food-csv

# Use CSV file

food = open('food.csv', newline='')
food_csv = csv.reader(food, delimiter=';')
food_name = [item[0] for item in food_csv]
food_left = food_name[1:10]
drinks_middle = food_name[10:]

drinks_dict = {}
drinks_dict_string = {}

count_i = 1
count_j = 1

# Function to connect Checkbutton and Entry (Food)

def costReference():
    food_string_1.set("0")
    food_string_2.set("0")

    if (food_var1.get() == 1):
        txt_food_1.configure(state=tk.NORMAL)
        txt_food_1.focus()
        txt_food_1.delete('0', tk.END)
        food_string_1.set("")
    elif (food_var1.get() == 0):
        txt_food_1.configure(state=tk.DISABLED)
        food_string_1.set("0")

    if (food_var2.get() == 1):
        txt_food_2.configure(state=tk.NORMAL)
        txt_food_2.focus()
        txt_food_2.delete('0', tk.END)
        food_string_2.set("")
    elif (food_var2.get() == 0):
        txt_food_2.configure(state=tk.DISABLED)
        food_string_2.set("0")

# 2 Checkbuttons and Entrys for Food

food_var1 = tk.IntVar()
food_var2 = tk.IntVar()

food_string_1 = tk.StringVar()
food_string_2 = tk.StringVar()


chck_food_1 = tk.Checkbutton(left_frame, variable=food_var1, onvalue=1,
                             offvalue=0, command=costReference)
chck_food_1.grid(column=0, row=1, sticky=tk.W)

chck_food_2 = tk.Checkbutton(left_frame, variable=food_var2, onvalue=1,
                             offvalue=0, command=costReference)
chck_food_2.grid(column=0, row=2, sticky=tk.W)

txt_food_1 = tk.Entry(left_frame, font=('arial', 15, 'normal'),
                    textvariable=food_string_1, bd=10, width=4,
                    justify='right', state=tk.DISABLED)
txt_food_1.grid(column=2, row=1)
txt_food_2 = tk.Entry(left_frame, font=('arial', 15, 'normal'),
                    textvariable=food_string_2, bd=10, width=4,
                    justify='right', state=tk.DISABLED)
txt_food_2.grid(column=2, row=2)

# Checkbutton and Entry for Drinks

for i in drinks_middle:
    drinks_dict[i] = tk.IntVar()
    chck_drinks = tk.Checkbutton(middle_frame, variable=drinks_dict[i],
                                 onvalue=1, offvalue=0)
    chck_drinks.grid(column=0, row=count_i, sticky=tk.W)
    count_i += 1

for j in drinks_middle:
    drinks_dict_string[j] = tk.StringVar()
    txt_drinks = tk.Entry(middle_frame, font=('arial', 15, 'normal'),
                          textvariable=drinks_dict_string[j], bd=10, width=4,
                          justify='right', state=tk.DISABLED)
    txt_drinks.grid(column=2, row=count_j)
    count_j += 1


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source