简体   繁体   中英

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. Within a given parent window you can only use one or the other.

将.pack()用于列表框和sb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM