浏览代码

Boolean input

Jovian (Netbook) 6 年之前
父节点
当前提交
9748ce652f
共有 2 个文件被更改,包括 37 次插入0 次删除
  1. 20 0
      checkbox.py
  2. 17 0
      confirm.py

+ 20 - 0
checkbox.py

@@ -0,0 +1,20 @@
+from PyInquirer import prompt, Separator
+
+widget = [
+	{
+		'type':'checkbox',
+		'name':'parts',
+		'message':'Choose parts to upgrade',
+		'choices':[Separator('= Weapons ='),
+		{'name':'Laser'},{'name':'Beam'},{'name':'Shotgun'},
+		Separator('= Others ='),
+		{'name':'Thruster'}, {'name':'Shield'},
+		{'name':'MedBay', 'disabled':'Already upgraded'},
+		{'name':'FTL', 'cheked':True}]
+	}
+]
+
+result = prompt(widget)
+print('Your answer is')
+print(result["parts"])
+

+ 17 - 0
confirm.py

@@ -0,0 +1,17 @@
+from PyInquirer import prompt
+
+widget = [
+	{
+		'type':'confirm',
+		'name':'ok',
+		'message':'Would you like to know the ultimate answer ?',
+		'default':True
+	}
+]
+
+result = prompt(widget)
+print('Your answer is')
+print(result["ok"])
+
+if result["ok"]:
+	print(42)