我在Windows 8計算機上使用Python 3.4和Tkinter創建GUI。如何動態更新ttk.combobox?
GUI具有在頂部的一些條目的輸入,然後一些組合框。我希望組合框從前面輸入(文件名,找到必要信息的行,分隔符類型等)描述的文本文件中獲取選項列表。我試圖使用postcommand,但它似乎首先運行並且從不更新,而不是每次訪問組合框的下拉菜單時更新。
datatypes = []
datatypes = ttk.Combobox(tab_loc, textvariable=std1, values=datatypes, postcommand=self.get_datatypes(datatypes,
self.flnm2.get(), self.hl2_text.get(), self.delim2.get(), self.fcd2_text.get())).grid(pady=v_pad,
padx=h_pad, row=8, column=1, sticky=EW)
def get_datatypes(self, lst, flnm, hl, delim, fcd):
# Problem: postcommand runs at start of GUI. Prevents updating.
lst += ["test", "worked?"]
print("stuff")
lst += flnm
lst += hl
try:
# open the file, get the line, break it apart.
except:
pass
self.flnm2
,self.hl2_text
,self.delim2
,和self.fcd2_text
是一些先前輸入。他們是StringVar。
當我運行此代碼時,組合框具有選項測試,工作?和兩個空白行(推測爲flnm
和hl
)。我打算有這樣的多個組合框,只是有不同的輸入,所以我需要一個功能,我可以給輸入,然後更新datatypes
。
我在做什麼錯?