如何将变量传递给对话框的选择?

时间:2016-06-23 10:35:46

标签: python dialog

我想有一个连接用户列表,为此选择了对话框。 这是我的第一个小python(3.5)脚本。

import sys
import psutil
import locale
import dialog
import pprint

locale.setlocale(locale.LC_ALL, '')
d = dialog.Dialog(dialog="dialog")
choices = []
i = 0;
users = psutil.users()
for user in users:
        item = ('{0}.'.format(i), user.name)
        choices.append(item)
        i += 1
choices.append(('X', "Exit"))
#pprint.pprint(choices)
#OUTPUT: [('0.', 'root'), ('1.', 'root'), ('X', 'Exit')]
#code, tag = d.menu("List", choices)
code, tag = d.menu("List", choices=[('0.', 'root'), ('1.', 'root'), ('X', 'Exit')])

我的问题是,为什么该对话框适用于内联定义的选项但可以 不是当我只提供已经定义的列表与内联定义中提供的列表相同时。

child_output.strip()))
dialog.DialogError: dialog-like terminated due to an error: the dialog-like program exited with status 3 (which was passed to it as the DIALOG_ERROR environment variable). Sometimes, the reason is simply that dialog was given a height or width parameter that is too big for the terminal in use. Its output, with leading and trailing whitespace stripped, was:

Error: Expected at least 6 tokens for --menu, have 4.

1 个答案:

答案 0 :(得分:0)

将它作为变量传递是不够的,例如:

code, tag = d.menu("List", choices)

应明确声明为:

code, tag = d.menu("List", choices=choices)