-1
我正在嘗試創建一個滾動條附加到列表框。我在這裏看到了一些類似的問題,我已經跟着他們並試圖做出同樣的問題,但他們的解決方案並不適合我。如何在列表框中添加TKinter滾動條
的問題是,這些行:
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