pythonliu97 发表于 2020-8-29 21:27:08

easygui示例的msgbox报错

求大佬帮忙解决!
报错如下:
=========================== RESTART: F:\daima\1.py ===========================

Traceback (most recent call last):
File "F:\daima\1.py", line 4, in <module>
    g.msgbox('welcome to my module program!')
TypeError: 'str' object is not callable
>>>
代码如下:
import easygui as g
import sys
while 1:
    g.msgbox('welcome to my module program!')
    msg = 'what do you want to learn from me ?'
    title = 'this is a small game'
    choices = ['laugh', 'cry','make a nice work' ]
    choice = g. choicebox(msg, title, choices)
    g. msgbox = ('your choice is '+choice)

    msg = 'do you want to make another choice ?'
    title = 'yes or no'
    if g.ccbox(msg, title):
      pass
    else:
      sys.exit()

qiuyouzhi 发表于 2020-8-29 21:37:25

改成这样:
import easygui as g
import sys
while 1:
    g.msgbox('welcome to my module program!')
    msg = 'what do you want to learn from me ?'
    title = 'this is a small game'
    choices = ['laugh', 'cry','make a nice work' ]
    choice = g. choicebox(msg, title, choices)
    g. msgbox('your choice is '+choice)

    msg = 'do you want to make another choice ?'
    title = 'yes or no'
    if g.ccbox(msg, title):
      pass
    else:
      sys.exit()

1q23w31 发表于 2020-8-30 08:43:22

import easygui as g
import sys
while 1:
    g.msgbox('welcome to my module program!')
    msg = 'what do you want to learn from me ?'
    title = 'this is a small game'
    choices = ['laugh', 'cry','make a nice work' ]
    choice = g. choicebox(msg, title, choices)
    if choice :
      g. msgbox('your choice is '+choice)

    msg = 'do you want to make another choice ?'
    title = 'yes or no'
    if g.ccbox(msg, title):
      pass
    else:
      sys.exit()

报错是因为你的choice可能返回的是NoneType,加一步判断即可解决
页: [1]
查看完整版本: easygui示例的msgbox报错