Python精灵模块的Listbox指令

所有命令 单独命令 屏幕命令 角色命令

单独命令 >> Python精灵模块的Listbox指令

简介:这是tkinter的Listbox组件,使用方法基本相同,只不过是绝对定位。
例子:
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()

writed by lixingqiu 关注"异编程"微信公众号,获取更多关于Python精灵模块的咨讯: