from sprites import Screen,Listbox,TK
def select(event):
# 获取被点击的项的索引
w = event.widget
print(w.curselection())
selected_index = int(w.curselection()[0])
selected_value = w.get(selected_index)
print(f"选中的项: {selected_value}")
screen = Screen()
screen.setup(600,600)
# 以引定位在x=80,y=50的坐标
lstbox = Listbox(80,50,width=24,height=10,
selectmode=TK.SINGLE) # 新建列表框
lstbox.insert(TK.END,"江西省萍乡市")# 添加到列表框中
lstbox.insert(TK.END,"安源区凤凰街")# 添加到列表框中
lstbox.insert(TK.END,"昭萍东路北桥和绿茵广场之间")# 添加到列表框中
lstbox.select_set(0)
lstbox.bind('<>', select)
screen.mainloop()
|