0

I'm using easygui.multchoicebox() to select a number of items in a tuple. How do I make a conditional that executes code when certain items from the tuple are selected?

Here is example code that does not work (nothing is returned):

from easygui import *

fieldnames = ["Yes", "No", "Maybe"]
choice = multchoicebox("Pick an option.", "", fieldnames)
if choice == fieldnames[0,1]:
    msgbox('Incomplete')
if choice == fieldnames[2]:
    msgbox('Complete')

It says that the list indices cannot be tuples. I changed the conditionals to strings and it did not work either (still nothing is returned):

from easygui import *

fieldnames = ["Yes", "No", "Maybe"]
choice = multchoicebox("Pick an option.", "", fieldnames)
if choice == "Yes" and "No":
    msgbox('Incomplete')
if choice == "Maybe":
    msgbox('Complete')

What is preventing the code from being executed? If easygui.multchoicebox() isn't designed from this, what module is?

Eric
  • 99
  • 2
  • 9

1 Answers1

2

You say

fieldnames[0, 1]

Essentially, you're passing a tuple (0, 1) as an index to fieldnames. Use this idiom instead:

if choice in fieldnames[0:2]:
    #dostuff
Joel Cornett
  • 24,192
  • 9
  • 66
  • 88