给你修改了下,主要的问题,列表的append()(这边要用append,不是extend,试一下就知道区别了)和remove()函数没有返回值,所以用变量接收后就是Noneimport easygui as p
class Variable():
def getVariable(self):
list_object = []
while True:
choice_variables = ["增加实例对象", "删除实例对象"]
user_choice1 = p.choicebox("请选择您的操作", "输入提示", choice_variables)
if user_choice1 == "增加实例对象":
Entity_object = p.enterbox("请输入实例对象", "增加提示")
if Entity_object != '':
list_object.append(Entity_object)
print(list_object)
set_object = set(list_object)
object_range = len(set_object)
print("此时类Variable中的实例对象一共有%d个" % object_range)
print("此时类中所有的实例对象为", set_object)
else:
print('未输入内容')
if user_choice1 == "删除实例对象" and user_choice1 != '':
Entity_object = p.enterbox("请输入实例对象", "删除提示")
if Entity_object != '' and Entity_object in list_object:
list_object.remove(Entity_object)
print(list_object)
set_object = set(list_object)
object_range = len(set_object)
print("此时类Variable中的实例对象一共有%d个" % object_range)
print("此时类中所有的实例对象为", set_object)
else:
print('未输入内容或输入的内容不在列表内')
a = Variable()
a.getVariable()
|