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.
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.
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.
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 !"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.