-1

So i have a basic question: how to use if and else statements correctly with easyGUI? This is what I have:

import easygui

msg = "Oh i see m9, choos your difficulty"
title = "Mountain Dew Franchise"
choices = ["Pro 360 noscoper(+1001)", "Dank skrubl0rd(-666)"]
choice = easygui.ynbox(msg, title, choices)

#if choices==choices[0]:
    easygui.msgbox("Good choos m20, let the skrubl0rd noscoping begin.")

#if choices==choices[1]:
    easygui.msgbox("Oh i see m8.")

The # lines seem to be the problem area

It does not let me go to either msgbox, but instead just closes the program, any help would be appreciated.

Andy
  • 49,085
  • 60
  • 166
  • 233
  • The if statement does not work any differently when using easygui than anywhere else. It's the values you're checking you should be worried about. – Lack Jan 11 '15 at 03:29

3 Answers3

1

The ynbox returns True or False, not one of your choices (that's just what it displays on the two buttons!). So, change your checks to if choice: and else: (and make sure your indentation's correct -- looks weird in your Q!-) and you should be fine.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
1
choice = easygui.ynbox(msg, title, choices)

This ynbox returns True or False. That means that choice can only be one of these two values.

if choices==choices[0]:

You are comparing if your list (choices) is equal to the value of your first element in the same list.


To make your program work, you need to modify your if section a bit.

if choice:
     easygui.msgbox("Good choos m20, let the skrubl0rd noscoping begin.")
else:
     easygui.msgbox("Oh i see m8.")

Since choice can only be True or False and the first option in your choices list become the True value, this logic will work.

Andy
  • 49,085
  • 60
  • 166
  • 233
0

A simple Example it may helpful:

from easygui import *


msg  = "Flavor"
title = "survey"
choices = ["vanila", "chocolate", "foo","strbry"]
choice = choicebox(msg, title, choices)

if choice == "foo":
   print "your choice is good" 
else:
   print "Try again its not a good choice !"
jax
  • 3,927
  • 7
  • 41
  • 70