所以我目前遇到的问题是我想根据用户在第一个中选择的内容更新第二个选项菜单。我想我必须在这里使用一个 lambda 函数来使框架更新或其他东西,但我不确定如何做到这一点。到目前为止,这是我的代码:
from tkinter import *
import time
class CustomerEntryForm(Frame):
def __init__(self):
Frame.__init__(self)
self.master.title("Customer Entry form:")
self.pack()
execute = True
thirtyMonthList = [4,6,9,11]
thirtyOneMonthList = [1,2,6,7,8,10,12]
monthList = []
dayList = []
for i in range(1,13):
monthList.append(i)
initialMonth = IntVar(self)
initialMonth.set(monthList[0])
initialDay = IntVar(self)
def resetDayOptionMenu():
for i in range(1,len(dayList)+1):
dayList.remove(i)
def setDayList():
resetDayOptionMenu()
if initialMonth.get() == 2:
for i in range(1, 29):
dayList.append(i)
initialDay.set(dayList[0])
elif initialMonth.get() in thirtyMonthList:
for i in range(1, 31):
dayList.append(i)
initialDay.set(dayList[0])
elif initialMonth.get() in thirtyOneMonthList:
for i in range(1, 32):
dayList.append(i)
initialDay.set(dayList[0])
self.om2 = OptionMenu(self, initialMonth, *monthList, command = setDayList())
self.om2.grid(row=0)
self.om = OptionMenu(self, initialDay, *dayList)
self.om.grid(row=1)
root = CustomerEntryForm()
root.mainloop()
我很感激任何帮助。谢谢。