import easygui as g g.enterbox('你好',title='我是标题',choices=['确定','取消'] 这段代码错在哪
时间: 2024-01-01 21:04:41 浏览: 33
您好!感谢您提供的代码。这段代码有一个小错误。在`enterbox`函数中,参数`choices`是用于指定按钮的文本选项,但是`enterbox`函数并不支持该参数。如果您想要自定义按钮文本,可以使用`buttonbox`函数。以下是修正后的代码示例:
```python
import easygui as g
msg = '你好'
title = '我是标题'
choices = ['确定', '取消']
result = g.buttonbox(msg, title=title, choices=choices)
if result == '确定':
g.msgbox('用户点击了确定按钮')
else:
g.msgbox('用户点击了取消按钮')
```
在上面的示例中,我们使用了`buttonbox`函数来实现自定义按钮文本的功能。根据用户的选择,我们显示相应的消息框。
希望这个修正对您有帮助!如果还有其他问题,请随时提问。
相关问题
python 中 easygui库 如何修改enterbox按钮值
要修改`easygui`库中`enterbox`函数的按钮值,您可以使用`buttonbox`函数来实现。`buttonbox`函数允许您自定义按钮的文本,并且与`enterbox`一样可以接受用户输入。下面是一个示例代码:
```python
from easygui import buttonbox
msg = "请输入您的姓名:"
title = "输入框示例"
choices = ["确定", "取消"] # 自定义按钮文本
result = buttonbox(msg, title, choices=choices)
if result == "确定":
# 用户点击了确定按钮
name = input("请输入您的姓名:")
print("您输入的姓名是:", name)
else:
# 用户点击了取消按钮
print("用户取消了输入")
```
在上面的示例中,我们使用`buttonbox`函数代替了`enterbox`函数,并通过`choices`参数传入了自定义的按钮文本。用户可以选择"确定"或"取消"按钮,如果选择了"确定",则会要求用户输入姓名并打印出来,如果选择了"取消",则会打印出取消的提示信息。
希望这个示例对您有帮助!如果还有其他问题,请随时提问。
easygui如何取消提示操作已超时?
您可以使用 easygui.msgbox() 函数的 timeout 参数来设置超时时间,例如:
```
import easygui
easygui.msgbox("Hello, world!", title="My Message Box", ok_button="OK", timeout=5)
```
这将在 5 秒后自动关闭消息框。如果您想要取消超时提示,可以使用 easygui.cancelbox() 函数,例如:
```
import easygui
if easygui.ccbox("Are you sure you want to quit?", title="My Confirmation Box", choices=("Yes", "No"), cancel_choice="No", timeout=10):
easygui.msgbox("Goodbye!", title="My Message Box", ok_button="OK")
else:
easygui.cancelbox("Operation cancelled.", title="My Message Box")
```
这将在 10 秒后自动选择 "No",并显示一个取消提示框。如果用户在超时前选择了 "Yes" 或 "No",则不会显示取消提示框。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)