0
私は多くの異なるオプションメニューがあるウィジェットを持っています。私は各オプションメニューの左側に適切なラベルを追加する必要があります。tkinterの各オプションメニューにラベルを付け加える
私のコードは次のようになります。
from tkinter import*
class MyOptionMenu(OptionMenu):
def __init__(self, master, status, *options):
self.var = StringVar(master)
self.var.set(status)
OptionMenu.__init__(self, master, self.var, *options)
self.config(font=('calibri',(8)),bg='white',width=20)
self['menu'].config(font=('calibri',(8)),bg='white')
root = Tk()
optionList1 = items1
optionList2 = items2
optionList3 = items3
optionList4 = items4
optionList5 = items5
lab1 = Label(root, text="condition №1", font="Arial 8", anchor='w')
mymenu1 = MyOptionMenu(root, '-', *optionList1)
lab2 = Label(root, text="condition №2", font="Arial 8", anchor='w')
mymenu2 = MyOptionMenu(root, '-', *optionList2)
lab3 = Label(root, text="condition №3", font="Arial 8", anchor='w')
mymenu3 = MyOptionMenu(root, '-', *optionList3)
lab4 = Label(root, text="condition №4", font="Arial 8", anchor='w')
mymenu4 = MyOptionMenu(root, '-', *optionList4)
lab = Label(root, text="Enter the date", font="Arial 8", anchor='w')
ent1 = Entry(root,width=20,bd=3)
lab5 = Label(root, text="condition №5", font="Arial 8", anchor='w')
mymenu5 = MyOptionMenu(root, '-', *optionList5)
lab1.pack(side="top",fill = "x")
mymenu1.pack(side="top",fill = "y")
lab2.pack(side="top",fill = "x")
mymenu2.pack(side="top",fill = "y")
lab3.pack(side="top", fill="x")
mymenu3.pack(side="top", fill="y")
lab4.pack(side="top", fill="x")
mymenu4.pack(side="top", fill = "y")
lab.pack(side="top", fill="x")
ent1.pack(side="top", fill="y")
lab5.pack(side="top", fill="x")
mymenu5.pack(side="top", fill = "y")
def save_selected_values():
global values1
values1 = [mymenu1.var.get(), mymenu2.var.get(), mymenu3.var.get(), mymenu4.var.get(), ent1.get(), mymenu5.var.get()]
print(values1)
button = Button(root, text="OK", command=save_selected_values)
button.pack()
root.mainloop()
結果は次のようになります。
しかし、私は、ドロップダウンリストで適切なラインになるように各ラベルを必要とする
Excelの場合、次のようになります。
ここで、列Bの各行はドロップダウンリストです。
私はfill = "x"
が行全体を埋めることを理解しますが、変更しようとするとさらに悪化します。
アドバイスをいただきありがとうございます。
文法を修正しようとしました。編集した内容が変更された場合は、自由にロールバックしてください。 – Lafexlos
@Lafexlosそれは私が言っていた私の元の意図を変えますが、あなたのバージョンはより良く聞こえるので、それを元に戻しません。もともと私はAskerがExcelの例でグリッドレイアウトを使用していたと言いたいので、tkinterで同じものを使用します。 –