0

I'm making an interface for my e-learning question which is on easy difficulty. is there anything wrong with the code? It keeps on saying there is an error on line 21. Whats the mistake?

import Tkinter
MathsEasyLevel1 = Tkinter.Tk()
MathsEasyLevel1.geometry("320x260")
MathsEasyLevel1.title("Mathematics Easy")
total = 0

getanswer = Tkinter.IntVar()


def userinput():
    Answer1 = getanswer.get()
    if Answer1 == 8 :
        total = total + 1

    else :
        total = total
        MathsEasyLevel1.withdraw()
        MathsEasyLevel1.deiconify()
    return

LabelName = Tkinter.Label (MathsEasyLevel1, text="Question 1", font("Impact",20)).grid(row=0,column=2,sticky="new")

LabelName = Tkinter.Label (MathsEasyLevel1, text="State the number of edges in a cube")
LabelName.pack()
TxtBoxName = Tkinter.Entry (MathsEasyLevel1, textvariable= getanswer)
TxtBoxName.pack()

MathsEasyLevel2 = Tkinter.Tk()
MathsEasyLevel2.geometry("320x260")
MathsEasyLevel2.title("Mathematics Easy")
MathsEasyLevel2.withdraw()

BtnName = Tkinter.Button (MathsEasyLevel1, text="Proceed", command=userinput).pack()
Matt
  • 14,007
  • 25
  • 88
  • 136

1 Answers1

2

There are a few problems I can see. Line 21 (LabelName = Tkinter.Label (MathsEasyLevel1, text="Question 1", font("Impact",20)).grid(row=0,column=2,sticky="new"), I presume) takes font as an argument in the form font = ("Impact",20), so your corrected code for this line would be:

LabelName = Tkinter.Label (MathsEasyLevel1, text="Question 1", font=("Impact",20)).grid(row=0,column=2,sticky="new")

Also, you are assigning the outcome of the grid method you are running to LabelName. You probably want to be doing this:

LabelName = Tkinter.Label (MathsEasyLevel1, text="Question 1", font=("Impact",20))
LabelName.grid(row=0,column=2,sticky="new")

This way you can reference LabelName, now the actual label, multiple times.

You also use the same variable name, LabelName, for two different Label widgets. This means a reference to the previous one is not kept which could cause problems at some stage. Another problem is that you mix the use of the grid packing method and the pack packing method in the same window, which is not a good idea. Try this instead:

LabelName1 = Tkinter.Label (MathsEasyLevel1, text="Question 1", font=("Impact",20))
LabelName1.grid(row=0,column=2,sticky="new")
LabelName2 = Tkinter.Label (MathsEasyLevel1, text="State the number of edges in a cube")
LabelName2.grid(row=1,column=0)
TxtBoxName = Tkinter.Entry (MathsEasyLevel1, textvariable= getanswer)
TxtBoxName.grid(row=2,column=0)

Obviously you can change the rows and columns as you want. The rest of your code looks fine to me!

Community
  • 1
  • 1
Rob Murray
  • 1,647
  • 6
  • 19
  • 30