【发布时间】:2017-08-27 08:36:33
【问题描述】:
我正在创建一个简单的 GUI 程序来管理优先级。
我已经成功地添加了将项目添加到列表框的功能。现在我想将该项目添加到 C# 中称为 List 的内容中。 Python中有这样的东西吗?
例如,在 C# 中,要向列表视图中添加一个项目,我首先要创建:
List<Priority> priorities = new List<Priority>();
...然后创建以下方法:
void Add()
{
if (listView1.SelectedItems.Count > 0)
{
MessageBox.Show("Please make sure you have no priorities selected!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txt_Priority.ReadOnly == true) { MessageBox.Show("Please make sure you refresh fields first!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); }
else
{
if ((txt_Priority.Text.Trim().Length == 0)) { MessageBox.Show("Please enter the word!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); }
else
{
Priority p = new Priority();
p.Subject = txt_Priority.Text;
if (priorities.Find(x => x.Subject == p.Subject) == null)
{
priorities.Add(p);
listView1.Items.Add(p.Subject);
}
else
{
MessageBox.Show("That priority already exists in your program!");
}
ClearAll();
Sync();
Count();
}
}
SaveAll();
}
【问题讨论】:
-
而你在搜索“Python 列表”时找不到任何信息?!
标签: python listview tkinter listbox