我正在尝试创建一个附加了滚动条的列表框。我在这里看到了一些类似的问题,我已经跟着他们并试图做同样的事情,但他们的解决方案并不适合我。
问题出在以下几行:
total_results_listbox.grid(row=0, sticky=W)
total_results_scrollbar.grid(row=0, column=1)
如果我省略该行:
total_results_scrollbar.grid(row=0, column=1)
然后我只能看到列表框。如果我省略该行:
total_results_listbox.grid(row=0, sticky=W)
然后我只能看到滚动条。 你能弄清楚我为什么会这样做吗?
我的整个代码是:
def create_results_frame(root):
results_frame = Frame(root)
total_results_listbox = Listbox(results_frame,background='white')
total_results_scrollbar = Scrollbar(total_results_listbox, orient=VERTICAL)
total_results_listbox.config(yscrollcommand=total_results_scrollbar.set)
total_results_scrollbar.configure(command=total_results_listbox.yview)
recipes_result = ["honey pancake", "american pancake1", "american pancake2", "american pancake3", "american pancake4",
"american pancake5", "american pancake6", "american pancake7", "american pancake8",
"american pancake9", "american pancake10", "american pancake11", "american pancake12"]
for recipe in recipes_result:
total_results_listbox.insert(END, recipe)
total_results_listbox.grid(row=0, sticky=W)
total_results_scrollbar.grid(row=0, column=1)
return results_frame