0

I would like to have an easyGUI multchoicebox display output based on the correct choices being made. The following doesn't work (i.e it doesn't show 'correct')

import easygui

fieldnames = ["Incorrect", "Correct", "Also Correct"]
choice = easygui.multchoicebox("Pick an option.", "", fieldnames)
if choice == fieldnames[1] and fieldnames[2]:
    easygui.msgbox('Correct!')
else:
    easygui.msgbox('Incorrect')

#Also tried:
#if choice == "Correct" and "Also Correct":

2 Answers2

1

You can use the "in" operator to check if the desired field was selected by the user.

Then, in order to apply the logic to both chosen values, simply add "and".

Here's the code, corrected and tested:

import easygui

fieldnames = ["Incorrect", "Correct", "Also Correct"]
choice = easygui.multchoicebox("Pick an option.", "", fieldnames)

if fieldnames[1] in choice and fieldnames[2] in choice:
    easygui.msgbox('Correct!')
else:
    easygui.msgbox('Incorrect')
Pitto
  • 8,229
  • 3
  • 42
  • 51
0
if choice == fieldnames[1] and fieldnames[2]:

is the same as

if (choice == fieldnames[1]) and fieldnames[2]:

which means that it will check if choice equals fieldnames[1] and if fieldnames[2] is "truthy". (Which should be True if you select "Correct").

What you probably wanted to check is:

if choice in ( fieldnames[1], fieldnames[2] ):
Mike Scotty
  • 10,530
  • 5
  • 38
  • 50