12_组件Listbox

Listbox

列表框
组件用于显示一个选择列表
Listbox 只能包含文本项目,所有项目的字体和颜色都要相同。根据组件的配置,用户可以从列表中选择一个或多个选项。
import tkinter as tk

window = tk.Tk()
window.title('hello thinter')
height = window.winfo_screenheight()
width = window.winfo_screenwidth()
window.geometry('400x300+%d+%d' % ((width - 400) / 2, (height - 300) / 2))
# 创建一个空列表
theLB = tk.Listbox(window)
theLB.pack()

# 往列表里添加数据
for item in ["国", "省", "市", "县", "镇", "村", "组"]:
    theLB.insert("end", item)

def check():
    print(theLB.curselection())
    if theLB.curselection():
        param = theLB.get(theLB.curselection())
        print("选择:", param)

tk.Button(window, text="获取值", command=check).pack()
tk.Button(window, text="删除值", command=lambda x=theLB: x.delete("active")).pack()
window.mainloop()
posted @   interesting5319  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示