[英]Why won't my listbox and scrollbar not work?
I am trying to make a listbox which has a scrollbar but the following code doesn't seem to show up on the code Please can someone help me fix it? 我正在尝试制作一个具有滚动条的列表框,但是以下代码似乎未显示在该代码上,请有人能帮助我修复它吗?
listbox = Listbox(window2, height = 5)
listbox.insert(1,"Yr9")
listbox.insert(1,"Yr10")
listbox.insert(1,"Yr11")
listbox.insert(1,"Yr12")
listbox.insert(1,"Yr13")
listbox.grid(row=3,column=1)
sb = Scrollbar(window2,orient=VERTICAL)
sb.pack()
listbox = Listbox(window2, yscrollcommand=sb.set)
sb.config(command=listbox.yview)
sb.pack(side=LEFT,fill=Y)
listbox.pack(side=LEFT, fill=BOTH, expand=1)
The problem is that both the scrollbar and listbox are in window2
, but you are using grid
for one and pack
for the other. 问题是滚动条和列表框都在window2
,但是您将grid
用于其中一个而将pack
用于另一个。 Within a given parent window you can only use one or the other. 在给定的父窗口中,您只能使用一个或另一个。
将.pack()用于列表框和sb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.