【发布时间】:2017-08-02 15:48:42
【问题描述】:
我是 python 的新手,不明白这个问题的其他答案。为什么当我运行我的代码时,int(weight[0]) 不会将变量“权重”转换为整数。尽量把它弄糊涂,因为我真的很新,仍然不太了解其中的大部分内容。这是我的代码的相关部分
weight = (lb.curselection())
print ("clicked")
int(weight[0])
print (weight)
print (type(weight))
这是我的脚本代码
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)
谢谢
当我运行代码时,它会出现TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
而我希望它将“权重”变量转换为整数,以便我可以将其用于数学运算。
完整回溯: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 must be a string, a bytes-like object or a number, not 'tuple'
【问题讨论】:
-
您的问题需要包括您的输出,以及它与您的预期有何不同的描述。如果引发异常,您应该包含完整的回溯。
-
我将其更改为包含它,尽管我是编码和 stackoverflow 的新手。
标签: python python-3.x tkinter