root = tk.Tk()
root.title("Root")
root.configure(bg = "#333333")
root.geometry("600x500")
root.resizable(False, False)
def Category(category):
y = 40
category_list = [['Refrigerator', 'Refrigerator', 'Refrigerator', 'Refrigerator', 'Refrigerator', 'Television', 'Television', 'Television', 'Television', 'Television'], ['GE', 'LG', 'Maytag', 'Samsung', 'Whirlpool', 'Hisense', 'LG', 'Samsung', 'Sony', 'TCL']]
category_item = category_list[0]
brand = category_list[1]
for x in range(len(category_item)):
if category_item[x] == category:
if category == "Television":
brand_button = Button(frame, text = brand[x], font = "Poppins, 10", bg = "#222222", fg = "#ffffff", width = 12, borderwidth = 0, highlightthickness = 0, activebackground = "#222222", activeforeground = "#ffffff", anchor = "w")
brand_button.bind("<Button-1>", lambda e:getTV(brand[x]))
brand_button.place(x = 40, y = y)
y += 35
else:
brand_button = Button(frame, text = brand[x], font = "Poppins, 10", bg = "#222222", fg = "#ffffff", width = 12, borderwidth = 0, highlightthickness = 0, activebackground = "#222222", activeforeground = "#ffffff", anchor = "w")
brand_button.bind("<Button-1>", lambda e:getFridge(brand[x]))
brand_button.place(x = 40, y = y)
y += 35
def getFridge(user_input):
record = ['LG', 'GE', 'Maytag', 'Samsung', 'Whirlpool']
for row in record:
if user_input == row:
print("This is", row)
def getTV(user_input):
record = ['Hisense', 'LG', 'Samsung', 'Sony', 'TCL']
for row in record:
if user_input == row:
print("This is", row)
Category("Refrigerator")
root.mainloop()
So, I'm creating a tk.Button using a for loop. And for the name of the button are the same, and all of them are able to do the command. However, the argument(brand[x]) that is given to the function are all the same which is (TCL).
The photo of the button
This is the result that I get, no matter which button that I clicked
What I want is the output will be the same as the name of the brand name. For example, when I clicked GE button, it will give output 'This is GE'
def getFridge(user_input**[GE]**):
record = ['LG', 'GE', 'Maytag', 'Samsung', 'Whirlpool']
for row in record:
if user_input**[GE]** == row**[GE]**:
print("This is", row**[GE]**)