Python中tkinter中控件的使用(6.Listbox列表框(添加滚动条))
Posted 飞飞阿
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python中tkinter中控件的使用(6.Listbox列表框(添加滚动条))相关的知识,希望对你有一定的参考价值。
import tkinter
win = tkinter.Tk()
win.title("Listbox列表框(添加滚动条)")
#win.geometry("800x600+600+100")
#tkinter.EXTENDED 可以使listbox支持shift和ctrl功能
lb=tkinter.Listbox(win,selectmode=tkinter.EXTENDED)
for item in["good","nice","handsome","very good","verynice"
, "nice1", "handsome1", "very good1", "verynice1"
, "nice2", "handsome2", "very good2", "verynice2","nice3","handsome3",
"very good3","verynice3","nice4","handsome4","very good5","verynice5"
, "nice5", "handsome5", "very good6", "verynice6"
, "nice6", "handsome6", "very good7", "verynice7"
, "nice7", "handsome7", "very good8", "verynice8", "nice8", "handsome8",
"very good9", "verynice9", "nice9", "handsome9", "very good0",
"verynice0" ]:
lb.insert(tkinter.END,item)
#按住shift,可以实现连选
#按住ctrl,可以实现多选
#滚动条
sc = tkinter.Scrollbar(win)
sc.pack(side=tkinter.RIGHT,fill=tkinter.Y)
lb.pack(side=tkinter.LEFT,fill=tkinter.BOTH)
#额外给属性赋值
#关联滚动条
lb.config(yscrollcommand=sc.set)
sc[‘command‘]=lb.yview#两个效果一样sc.configure(command=lb.yview)
win.mainloop()
以上是关于Python中tkinter中控件的使用(6.Listbox列表框(添加滚动条))的主要内容,如果未能解决你的问题,请参考以下文章
Python中tkinter中控件的使用(6.Listbox列表框(单击多选))
python tkinter 怎么改变控件的形状,比如将按钮改成圆形的