如何在python tkinter中将滚动条添加到列表框?

时间:2018-05-08 03:55:30

标签: python tkinter

# create the listbox widgets
def onselect(evt):
    # Note here that Tkinter passes an event object to onselect()
    w = evt.widget
    index = int(w.curselection()[0])
    value = w.get(index)
    print(value)

listbox = Listbox(main_frame, selectmode=tk.SINGLE)
listbox.config(width=int(screen_width/50), height=int(screen_width/50))

for index in range(0, 5):
    listbox.insert(tk.END, "video"+str(index))

listbox.yscrollcommand = True
# listbox.grid(row=1, column=2)
listbox.place(x=screen_width-int(screen_width/3), y=0)


# <Double-1> for double click
listbox.bind('<Double-1>', onselect)
selection = listbox.curselection()

我无法为listbox添加滚动条,而错误会突然显示"Scrollbar" is not defined。有谁能够帮我?

0 个答案:

没有答案