鱼C论坛

 找回密码
 立即注册
查看: 2077|回复: 2

easygui示例的msgbox报错

[复制链接]
发表于 2020-8-29 21:27:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
求大佬帮忙解决!
报错如下:
  1. =========================== RESTART: F:\daima\1.py ===========================
  2. [0]
  3. Traceback (most recent call last):
  4.   File "F:\daima\1.py", line 4, in <module>
  5.     g.msgbox('welcome to my module program!')
  6. TypeError: 'str' object is not callable
  7. >>>
复制代码

代码如下:
  1. import easygui as g
  2. import sys
  3. while 1:
  4.     g.msgbox('welcome to my module program!')
  5.     msg = 'what do you want to learn from me ?'
  6.     title = 'this is a small game'
  7.     choices = ['laugh', 'cry','make a nice work' ]
  8.     choice = g. choicebox(msg, title, choices)
  9.     g. msgbox = ('your choice is '+choice)

  10.     msg = 'do you want to make another choice ?'
  11.     title = 'yes or no'
  12.     if g.ccbox(msg, title):
  13.         pass
  14.     else:
  15.         sys.exit()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-29 21:37:25 | 显示全部楼层
改成这样:
  1. import easygui as g
  2. import sys
  3. while 1:
  4.     g.msgbox('welcome to my module program!')
  5.     msg = 'what do you want to learn from me ?'
  6.     title = 'this is a small game'
  7.     choices = ['laugh', 'cry','make a nice work' ]
  8.     choice = g. choicebox(msg, title, choices)
  9.     g. msgbox('your choice is '+choice)

  10.     msg = 'do you want to make another choice ?'
  11.     title = 'yes or no'
  12.     if g.ccbox(msg, title):
  13.         pass
  14.     else:
  15.         sys.exit()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-30 08:43:22 | 显示全部楼层
  1. import easygui as g
  2. import sys
  3. while 1:
  4.     g.msgbox('welcome to my module program!')
  5.     msg = 'what do you want to learn from me ?'
  6.     title = 'this is a small game'
  7.     choices = ['laugh', 'cry','make a nice work' ]
  8.     choice = g. choicebox(msg, title, choices)
  9.     if choice :
  10.         g. msgbox('your choice is '+choice)

  11.     msg = 'do you want to make another choice ?'
  12.     title = 'yes or no'
  13.     if g.ccbox(msg, title):
  14.         pass
  15.     else:
  16.         sys.exit()
复制代码

报错是因为你的choice可能返回的是NoneType,加一步判断即可解决
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-26 13:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表