こんにちは、お役に立てるかもしれません。私はPythonとコーディング全般に不慣れです。私は、いくつかのリストを持ち、1 つのリストから選択し、その最初の選択に基づいて別のリストにデータが入力されるという基本的な概念のプログラムに取り組んでいます。GUI を作成できました。さまざまな形式の「リストボックス」を作成できました。その「リストボックス」のインデックスを取得する方法を示すチュートリアルに従うことができましたが、 2番目のリストボックスに、最初のボックスで行った選択のために作成したリストを入力することができました. チェックボックスも試してみましたが、それに近づきましたが、まだサイコロはありません。
以下の提供されたコードは、2 番目のリストを Python シェルに出力できるという意味で機能しますが、GUI でリストボックスを設定すると、そこに入力することができません。何も起こりません。そして、このコードにはリストボックスがなく、2番目のリストが入力されていないことがわかっています。したがって、このコードでは、「ブランド」の選択肢が「りんご」の場合、リストボックスに「modelA」からリストを入力する必要があります。または、チェックボックスが実際に存在せず、「ブランド」のアイテムが独自のリストボックスにある場合。どんな方向性でも、私ができることよりもはるかに役立つかもしれません. 再度、感謝します。
Python 3.3.2 Mac OS X 10.8.5
from tkinter import *
#brand would be for first listbox or checkboxes
brand = ['Apples','Roses', 'Sonic', 'Cats']
#model* is to be filled into the 2nd listbox, after selection from brand
modelA = ['Ants', 'Arrows', 'Amazing', 'Alex']
modelR = ['Early', 'Second', 'Real']
modelS= ['Funny', 'Funky']
modelC= ['Cool', 'Daring', 'Double']
#create checkboxes
def checkbutton_value():
if(aCam.get()):
print("Models are: ", modelA)
if(rCam.get()):
print("Models are: ", modelR)
if(sCam.get()):
print("Models are: ", modelS)
if(cCam.get()):
print("Models are: ", modelC)
#create frame, and check checkbuttons state, print value of model
root = Tk()
aCam = IntVar()
rCam = IntVar()
sCam = IntVar()
cCam = IntVar()
#Checkbutton functions
apples = Checkbutton(root, text = "Apples", variable=aCam, command=checkbutton_value)
apples.pack(anchor="w")
roses = Checkbutton(root, text = "Roses", variable=rCam, command=checkbutton_value)
roses.pack(anchor="w")
sonic = Checkbutton(root, text = "Sonic", variable=sCam, command=checkbutton_value)
sonic.pack(anchor="w")
cats = Checkbutton(root, text = "Cats", variable=cCam, command=checkbutton_value)
cats.pack(anchor="w")
#general stuff for GUI
root.title('My Brand')
root.geometry("800x300")
root.mainloop()