Python中tkinter中控件的使用(6.Listbox列表框(添加滚动条)),,import tki


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列表框(添加滚动条))

评论关闭