Easygui.msgbox ('you Entered ' + Flavour) Typeerror: Must Be Str, Not Nonetype
import easygui flavour = easygui.enterbox('What is your favourite ice cream flavour?') easygui.msgbox ('You entered ' + flavour) What do I do here so that when I hit the 'cancel
Solution 1:
this will do it
import easygui
while True:
flavour = easygui.enterbox('What is your favourite ice cream flavour?(type quit to quit)')
a = bool(flavour)
if a == False:
easygui.msgbox('you did not enter something')
elif a == True:
if flavour == 'quit':
break
else:
easygui.msgbox ('You entered ' + flavour)
(i can make the program better but bigger and larger)
Solution 2:
What is happening is that msgbox
wants the message to be string. However, if you hit cancel, flavour
is a NoneType
object. You can add an if statement to make sure your code does not error out if you hit cancel. Do something like:
flavour = easygui.enterbox('What is your favourite ice cream flavour?')
if flavour is not None:
easygui.msgbox ('You entered ' + str(flavour))
else:
pass
Post a Comment for "Easygui.msgbox ('you Entered ' + Flavour) Typeerror: Must Be Str, Not Nonetype"