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
15.1k28 gold badges109 silver badges161 bronze badges
asked Feb 16, 2016 at 10:34
1
  • 1
    I would be better if you add the error msg in your stackoverflow question. Commented Feb 16, 2016 at 10:38

1 Answer 1

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!

answered Feb 16, 2016 at 10:51
Sign up to request clarification or add additional context in comments.

2 Comments

can you please help me to figure out the problem below? Thanks
@MohdFareezuanKechik If you found my answer helpful feel free to accept the answer by clicking on the tick!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.