Python Forum
GUI calculation mistake
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI calculation mistake
#1
Hi all,

Can anyone tell me why my calculation (total_hscore (at the end of the code) is coming to zero please?
Thanks,

def openHistory():
    global total_hscore
  
    newWindow=Toplevel(mgui)
    newWindow.title("History")
    newWindow.configure(bg="dark red")
    newWindow.geometry("800x800")
    Label1=Label(newWindow,text="HISTORY",bg="dark red",fg="white").place(x=360,y=1)
    Label(newWindow,text="In which year did World War II end?",bg="dark red",fg="white").place(x=275,y=25)
    Label(newWindow,text="A. 1945",bg="dark red",fg="white").place(x=215,y=60)
    Label(newWindow,text="B. 1942",bg="dark red",fg="white").place(x=315,y=60)
    Label(newWindow,text="C. 1980",bg="dark red",fg="white").place(x=415,y=60)
    Label(newWindow,text="D. 2021",bg="dark red",fg="white").place(x=515,y=60)

    options = StringVar(newWindow)
    ho1=OptionMenu(newWindow,options, "A","B","C","D")
    ho1.config(bg="dark red",fg="white",width=10,height=1)
    ho1.place(x=305,y=100)

    if options=="A":
        hscore1=1
       
    else:
        hscore1=0
    
    Label(newWindow,text="In which year did World War II start?",bg="dark red",fg="white").place(x=275,y=135)
    Label(newWindow,text="A. 2016",bg="dark red",fg="white").place(x=215,y=175)
    Label(newWindow,text="B. 1914",bg="dark red",fg="white").place(x=315,y=175)
    Label(newWindow,text="C. 1939",bg="dark red",fg="white").place(x=415,y=175)
    Label(newWindow,text="D. 1936",bg="dark red",fg="white").place(x=515,y=175)

    options = StringVar(newWindow)
    ho2=OptionMenu(newWindow,options, "A","B","C","D")
    ho2.config(bg="dark red",fg="white",width=10,height=1)
    ho2.place(x=305,y=205)

    if options=="C":
        hscore2=1
    else:
        hscore2=0
    
    Label(newWindow,text="What was the name of the machine used to create German and Japanese codes?",bg="dark red",fg="white").place(x=110,y=240)
    Label(newWindow,text="A. Axis",bg="dark red",fg="white").place(x=215,y=275)
    Label(newWindow,text="B. Enola",bg="dark red",fg="white").place(x=315,y=275)
    Label(newWindow,text="C. Blitz",bg="dark red",fg="white").place(x=415,y=275)
    Label(newWindow,text="D. Enigma",bg="dark red",fg="white").place(x=515,y=275)
    
    options = StringVar(newWindow)
    ho3=OptionMenu(newWindow,options, "A","B","C","D")
    ho3.config(bg="dark red",fg="white",width=10,height=1)
    ho3.place(x=305,y=310)
    

    if options =="D":
        hscore3=1
    else:
        hscore3=0
    
    Label(newWindow,text="Which countries fought on the Eastern Front of World War II? ",bg="dark red",fg="white").place(x=200,y=350)
    Label(newWindow,text="A. Germany/Soviet Union",bg="dark red",fg="white").place(x=105,y=400)
    Label(newWindow,text="B. Britain/Germany",bg="dark red",fg="white").place(x=300,y=400)
    Label(newWindow,text="C. Switzerland/Italy",bg="dark red",fg="white").place(x=450,y=400)
    Label(newWindow,text="D. United States/Japan",bg="dark red",fg="white").place(x=600,y=400)

    options = StringVar(newWindow)
    ho4=OptionMenu(newWindow,options, "A","B","C","D")
    ho4.config(bg="dark red",fg="white",width=10,height=1)
    ho4.place(x=305,y=440)
    
    if options=="A":
        hscore4=1
    else:
        hscore4=0
    
    Label(newWindow,text="What was the code name for the allied invasion of Normandy?",bg="dark red",fg="white").place(x=200,y=480)
    Label(newWindow,text="A. VJ Day",bg="dark red",fg="white").place(x=180,y=520)
    Label(newWindow,text="B. VE Day",bg="dark red",fg="white").place(x=280,y=520)
    Label(newWindow,text="C. D-Day",bg="dark red",fg="white").place(x=380,y=520)
    Label(newWindow,text="D. French Resistance",bg="dark red",fg="white").place(x=480,y=520)

    options = StringVar(newWindow)
    ho5=OptionMenu(newWindow,options, "A","B","C","D")
    ho5.config(bg="dark red",fg="white",width=10,height=1)
    ho5.place(x=305,y=560)

    
    if options =="C":
        hscore5=1
    else:
        hscore5=0
   
    Label(newWindow,text="In 1945 which two Japanese cities were nuclear bombs detonated?",bg="dark red",fg="white").place(x=160,y=600)
    Label(newWindow,text="A. Hiroshima/Nagasaki",bg="dark red",fg="white").place(x=170,y=640)
    Label(newWindow,text="B. Tokyo/Hiroshima",bg="dark red",fg="white").place(x=340,y=640)
    Label(newWindow,text="C. Tokyo/Nagasaki",bg="dark red",fg="white").place(x=490,y=640)

    options = StringVar(newWindow)
    ho6=OptionMenu(newWindow,options, "A","B","C","D")
    ho6.config(bg="dark red",fg="white",width=10,height=1)
    ho6.place(x=305,y=668)

    if options=="A":
        hscore6=1
    else:
        hscore6=0

    hbt20=Button(newWindow,text="Continue",bg="dark red",fg="white",width=14,height=1,command=openSport).place(x=305,y=703)

    
    total_hscore=hscore1+hscore2+hscore3+hscore4+hscore5+hscore6
    print(total_hscore)
Reply


Messages In This Thread
GUI calculation mistake - by rturus - Mar-01-2021, 04:15 PM
RE: GUI calculation mistake - by deanhystad - Mar-01-2021, 05:38 PM
RE: GUI calculation mistake - by deanhystad - Mar-01-2021, 05:54 PM
RE: GUI calculation mistake - by joe_momma - Mar-02-2021, 06:57 PM
RE: GUI calculation mistake - by rturus - Mar-03-2021, 11:39 AM
RE: GUI calculation mistake - by deanhystad - Mar-03-2021, 02:10 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020