Python Forum
GUI calculation mistake
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI calculation mistake
#2
Because you got all the answers wrong. Actually you got all the answers wrong twice.

From your code:
    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
This creates an OptionMenu and binds it to a StringVar(). So far, so good. But then it tries to test the value of the StringVar() and that is where you are twice wrong. First off, to get the value selected by the OptionMenu you use options.get(). options is a StringVar and it is never going to match "C". options.get() may match "C", but not until you fix your other problem.

Your second problem is you don't wait for the questions to be answered. Your program tests the answer as soon as the widgets are made. None of the OptionMenus are set at this time, so options.get() returns 0.

You need to wait until all the questions are answered before you can calculate the score. This means you'll need a different "options" StringVar() for each question, and you only "get()" the answers from those options when you press the button to continue.
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