基本上,我在调用#Topscores方法时创建了另一个窗口。在此窗口中有一个列表框和一个排序按钮。
当我点击排序按钮时,它会假设对列表框中的值进行排序,但每当我点击排序按钮时,它会显示
AttributeError:'int'对象没有属性'get'
在这行代码上
temp_list = list(topscoreslistbox.get(0,END))
任何人都可以帮我这个吗?
顺便说一句,Listbox如何获取其值来自#TopscoresStop方法。
def main():
root = Tk()
root.wm_attributes("-topmost", 1)
root.title("Solar Car Racing")
root.geometry("1600x900")
topscoreslistbox = 0
sw = StopWatch(root)
sw.place(x=120, y=80)
sw2 = StopWatch2(root)
sw2.place(x=840, y=80)
def Topscores():
toplevel() = Toplevel()
toplevel.title("Top Scores")
topscoreslistbox = Listbox(toplevel, selectmode=EXTENDED, height=3, width=20, font=("Helvetica", 26))
topscoreslistbox.pack(side=RIGHT, fill=BOTH, expand=1, pady=5, padx=2)
first = Label(toplevel, text=("1st"), font=("Algerian", 30))
first.pack(side=TOP)
second = Label(toplevel, text=("2nd"), font=("Algerian", 30))
second.pack(side=TOP)
third = Label(toplevel, text=("3rd"), font=("Algerian", 30))
third.pack(side=TOP)
Buttonsort = Button(toplevel, text="Sort", command=Sort)
Buttonsort.pack()
def TopscoresStop():
tempo = sw._elapsedtime - sw.lapmod2
tempo2 = sw2._elapsedtime2 - sw2.lapmod2
if sw._running:
sw.after_cancel(sw._timer)
sw._elapsedtime = time.time() - sw._start
sw._setTime(sw._elapsedtime)
sw._running = 0
if len(sw.laps) == 3:
return
sw.laps.append(sw._setLapTime(tempo))
topscoreslistbox.insert(END, (str(sw.one.get()) , "%.2f" % sw._elapsedtime))
topscoreslistbox.yview_moveto(1)
if sw2._running2:
sw2.after_cancel(sw2._timer2)
sw2._elapsedtime2 = time.time() - sw2._start2
sw2._setTime(sw2._elapsedtime2)
sw2._running = 0
if len(sw2.laps) == 3:
return
sw2.laps.append(sw2._setLapTime(tempo))
topscoreslistbox.insert(END, (str(sw.two.get()) , "%.2f" % sw2._elapsedtime2))
topscoreslistbox.yview_moveto(1)
def Sort():
temp_list = list(topscoreslistbox.get(0,END))
temp_list.sort()
topscoreslistbox.delete(0, END)
for item in temp_list:
topscoreslistbox.insert(END, item)