我在python上是全新的,并且不理解这个问题的其他答案.为什么当我运行我的代码时,不会int(weight[0])将变量"weight"转换为整数.尽力使其愚蠢,因为我真的很新,但仍然不太了解它的大部分内容.这是我的代码的相关部分
weight = (lb.curselection())
print ("clicked")
int(weight[0])
print (weight)
print (type(weight))
Run Code Online (Sandbox Code Playgroud)
并且这是我脚本的代码
lb = Listbox(win, height=240)
lb.pack()
for i in range(60,300):
lb.insert(END,(i))
def select(event):
weight = (lb.curselection())
print ("clicked")
int(weight[0])
print (weight)
print (type(weight))
lb.bind("<Double-Button-1>", select)
Run Code Online (Sandbox Code Playgroud)
谢谢
当我运行代码时,它会出现,TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
我希望它将"weight"变量转换为整数,所以我可以将它用于数学运算.
完全追溯:Traceback (most recent call last):
File "C:\Users\Casey\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:/Users/Casey/AppData/Local/Programs/Python/Python36-32/s.py", line 11, in select
int(weight)
TypeError: int() argument …