如何创建交互式选择? [英] How do I create an interactive selection?

查看:118
本文介绍了如何创建交互式选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Python中创建一个交互式选择"(不确定我的措词是否正确,请看下面的示例),它允许用户按下上下键选择一个选项,然后返回以确认该选项,然后继续执行脚本.终端中的示例输出如下所示:

I want to create an "interactive selection" in Python (not sure if I worded that correctly, look at the example below) that lets users press their up and down keys to choose an option and return to confirm it, then it continues with the script. An example output in a terminal would be something like this:

$ python script.py
Please select an option.

  [ ] Option 1
  [ ] Option 2
  [*] Option 3

You have chosen: Option 3

在打印出第一个字符串之后,用户可以使用箭头键选择由星号标记的选项.该脚本看起来像这样:

After that first string had printed, the user could use their arrow keys to choose their option marked by the asterisk. The script would look somewhat like this:

print 'Please select an option.'
option = interactive_choice(['Option 1', 'Option 2', 'Option 3'])
print 'You have chosen: ' + option

有人知道该怎么做吗?

推荐答案

在Windows上,您对此类事情的了解非常有限.您可能要访问的库是 wcurses Wconsio . 请注意,我自己都不使用这些库.使用类似 Boa构造函数这样的IDE来设计GUI可能看起来更好,但是,毫无疑问,这要困难得多.

You are very limited with these kind of things on Windows. Libraries you may want to look in to are wcurses, PDCurses and Wconsio. Please note I used neither of these libraries myself. You also might be better off designing a GUI with a IDE like Boa Constructor that looks like a terminal, but no doubt that's considerably more difficult.

这篇关于如何创建交互式选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆