I am making a simple tkinter GUI with Python and I need to have about 10 or more labels to place. I place the labels using the grid method but after a certain amount it comes up with an error saying “TypeError: Label object is not callable”. Here is the code for the labels and the grid placing:
UnitPointLabel = ttk.Label(root, text = unit_points)
UnitLabel = ttk.Label(root, text = unit)
HQ1 = ttk.Label(root, text = "HQ:")
HQ2 = ttk.Label(root, text = "HQ:")
Elite1 = ttk.Label(root, text = "Elite:")
Elite2 = ttk.Label(root, text = "Elite:")
Elite3 = ttk.Label(root, text = "Elite:")
Troop1 = ttk.Label(root, text = "Troop:")
Troop2 = ttk.Label(root, text = "Troop:")
Troop3 = ttk.Label(root, text = "Troop:")
Troop4 = ttk.Label(root, text = "Troop:")
Troop5 = ttk.Label(root, text = "Troop:")
Troop6 = ttk.Label(root, text = "Troop:")
Fast_Attack1 = ttk.Label(root, text = "Fast Attack:")
Fast_Attack2 = ttk.Label(root, text = "Fast Attack:")
Heavy_Support1 = ttk.Label(root, text = "Heavy Support:")
Heavy_Support2 = ttk.Label(root, text = "Heavy Support:")
Heavy_Support3 = ttk.Label(root, text = "Heavy Support:")
UnitPointLabel.grid(row = 3, column = 7)
HQ1.grid(row = 3, column = 5)
HQ2.grid(row = 4, column = 5)
Troop1.grid(row = 5, column = 5)
Troop2.grid(row = 6, column = 5)
Troop3.grid(row = 7, column = 5)
Troop4.grid(row = 8, column = 5)
Troop5.grid(row = 9, column = 5)
Troop6.grid(row = 10, column = 5)
Fast_Attack1.grid(row = 11, column = 5)
Fast_Attack2.grid(row = 12, column = 5)
Stops working here: Heavy_Support1(row = 3, column = 6)
Heavy_Support2(row = 2, column = 6)
Heavy_Support3(row = 3, column = 6)
As you can see I tried moving the rows and columns around but its still not working. Anyone know why this is happening?
First rule of debugging: assume the error message is telling the truth. What does it say? It says “Label object is not callable”. That means you have some object that is an instance of a Label object, and you are trying to call it. For example, “foo=Label(…); …; foo()”.
So, looking at your code, what label objects are you trying to call? Take a look at these three lines:
Looking back up through your code I see that Heavy_Support1 (et al.) are all instances of Label, and you are indeed trying to call it.
To make a long story short, it looks like you forgot to add
.gridon those lines. They should be: