我是python中的新成員,並且不明白此問題的其他答案。爲什麼當我運行我的代碼時,int(weight[0])
沒有將變量「weight」轉換爲整數。儘量減少它,因爲我真的很新,但仍然不太瞭解它。這裏是我的代碼的相關部分在Python中將元組轉換爲int
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'
您的問題需要包含您的輸出,並描述它與預期的不同之處。如果發生異常,應該包含完整的回溯。 – skrrgwasme
我改變它包括,謝謝,雖然我是新的編碼和計算器。 –