これは間違いなく初心者の質問です。Python 2.7 で Tkinter のグリッド レイアウト マネージャーを使用しています。クリックするとリストボックスを非表示にするボタンが必要です。これまでの私のコードは次のとおりです。
from Tkinter import *
root = Tk()
frame = Frame(root)
pyList = ["Eric", "Terry", "Graham", "Terry", "John", "Carol?", "Michael"]
arbList = ['ham', 'spam', 'eggs', 'potatos', 'tots', 'home fries']
pythons = Listbox(frame, width=10, height=5, selectmode=EXTENDED, exportselection=0)
food = Listbox(frame, width=10, height=5, selectmode=EXTENDED, exportselection=0)
def hider():
if pythons.selection_includes(4):
food.lower()
elif pythons.selection_includes(0):
food.lift()
b2 = Button(frame, text="Hide!", command=hider)
b2.grid(row=2, column=1)
food.grid(row=0, column=1)
pythons.grid(row=1, column=1, pady=10)
frame.grid()
for python in pyList:
pythons.insert('end', python)
for thing in arbList:
food.insert('end', thing)
root.mainloop()
残念ながら、これをいじると、リストボックスをフレームの上または下に持ち上げたり下げたりできないというエラーがスローされるようです。これは pack() マネージャーで動作するようになりましたが、grid() では動作しません。
私は何が欠けていますか?