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()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!