【发布时间】:2015-09-03 21:31:58
【问题描述】:
我正在 Windows 8 计算机上使用 Python 3.4 和 Tkinter 创建 GUI。
GUI 顶部有一些 Entry 输入,然后是一些组合框。我希望组合框从先前输入(文件名、找到必要信息的行、分隔符类型等)描述的文本文件中获取选项列表。我正在尝试使用 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。
当我运行此代码时,组合框有选项 test, working? 和两个空行(大概是 flnm 和 hl)。我计划有多个这样的组合框,只是输入不同,所以我需要一个可以输入然后更新datatypes的函数。
我做错了什么?
【问题讨论】:
标签: python-3.x combobox tkinter