调用类中的对象,总是错误
自己用easygui写的程序,到最后步可以调用self.weight self.heigt self.depth这三个参数并返回,self.door_header_height和self.door_header_weight这两个函数,无论如何都调用不了 显示类型错误,str和int和list都显示错误,有没有大佬来解答下源码如下
import easygui as f
class Login_data:
def __init__(self):
#登录窗口的数据,包括帐号和密码
self.account_num = '123'
self.password = '123'
self.msg = '请输入正确的帐号和密码'
self.title = '帐号中心'
self.list_enterbox = ['用户名','密码']
#登录信息的判定函数
def getlogin(self,x,y):
if x == self.account_num and y == self.password:
return False
elif x == ''or y == '':
return True
else:
return True
class Choice_box:
def __init__(self):
self.msg = '请选择下一步'
self.title = '选择中心'
self.choices = ['提供门洞尺寸,计算房门尺寸','提供柜体尺寸,报价整个柜体']
class Doorway:
def __init__(self):
self.msg = '高度,宽度,深度为必填项!'
self.title = '门洞数据'
self.list_doorway = ['门洞高度','门洞宽度','门洞深度','套线宽度','外到顶','内到顶','门洞左侧离墙距离','门洞右侧离墙距离']
def getdoor(self,x):
#计算房门的宽度
if x == '' and x == '':
self.weight = int(x) - 55
if x != '' and x =='':
if int(x)-10 < int(x):
self.weight = int(x) - 55
elif int(x)-10 == int(x):
self.weight = int(x) - 55
else:
self.weight = int(x) - 55 - (int(x)-10-int(x))
if x == '' and x !='':
if int(x)-10 < int(x):
self.weight = int(x) - 55
elif int(x)-10 == int(x):
self.weight = int(x) - 55
else:
self.weight = int(x) - 55 - (int(x)-10-int(x))
#计算房门的高度
if x =='' and x =='':
self.height = int(x) - 45
self.door_header_height = 0
self.door_header_weight = 0
if x !='' and x =='':
if int(x)-int(x) <= int(x)-15:
self.height = int(x)-10-(int(x)+8)
self.door_header_height = 0
self.door_header_weight = 0
else:
self.height = int(x) - 45
self.door_header_height = int(x)-int(x)-45
self.door_header_weight = int(self.weight) + 30
if x !='' and x =='':
if int(x)-int(x) <= x-15:
self.height = int(x)-10-(int(x)+8)
self.door_header_height = 0
self.door_header_weight = 0
else:
self.height = int(x) - 45
self.door_header_height = int(x)-int(x)-45
self.door_header_weight = int(self.weight) + 30
#计算房门的深度
self.depth = int(x)-5
return
login = Login_data()
login_message = []
login_return = 1
n = 0
while login_return:
login_message = f.multenterbox(login.msg,login.title,fields = login.list_enterbox,values = login_message )
login_return = login.getlogin(login_message,login_message)
choice = Choice_box()
choice_message = f.choicebox(choice.msg,choice.title,choices = choice.choices)
if choice_message == choice.choices:
doorway = Doorway()
doorwaymessage = f.multenterbox(doorway.msg,doorway.title,fields = doorway.list_doorway)
doormessage = doorway.getdoor(doorwaymessage)
print(doormessage)
print(doorway.door_header_height())
if choice_message == choice.choices:
pass
你的代码中完全没有定义 door_header_height 和 door_header_weight 这两个函数
而是对 door_header_height 和 door_header_weight两个变量 进行了赋值,为确切的数值,肯定无法调用的
举个例子你想想,如果 a = 1 ,此时 a 为 int整型数据,然后你却想调用这个数据即: a() ,相当于 1() ,肯定会导致报错 Twilight6 发表于 2021-6-6 22:08
你的代码中完全没有定义 door_header_height 和 door_header_weight 这两个函数
而是对 door_header_h ...
谢谢大佬!!!懂了懂了 写着写着写迷糊了
页:
[1]