如何将一个tkinter组合框小部件添加到也具有文本输入小部件的gui?

时间:2016-01-26 17:01:10

标签: python user-interface combobox tkinter

我正在开发一个带有文本输入窗口小部件的gui,它根据表中的记录数重新生成。我正在使用每个字段列表,每个字段都创建为一个条目小部件。对于这些字段中的至少一个,我想设置一个组合框,其值可供用户选择。我一直在玩添加一个组合框到根(我刚刚插入了一个样本),但是当我运行脚本时它没有显示出来。我没有收到错误,gui显示所有输入框,但不显示组合框。有没有人有任何想法:以下是一些代码:

import arcpy, tkMessageBox, ctypes, ttk
from Tkinter import *

mosaicD = r'C:\temp\temp.gdb\mapIndex_MD_test'
mapIndexTbl = r'C:\temp\temp.gdb\mapIndexTestTable'
formFields = ['County', 'Route', 'PMB', 'PME', 'Map_Sheet_Desc', 'HangingFileGroup', 'MapSubSet', 'MapSubSetStatus', 'Shtext', 'Status',
 'SubStatus', 'MapDatum', 'Geo_Referenced_Datum', 'MapScale', 'CAD', 'DrawingDate', 'FileExtention','Original_MrSID_Filename']
fields = arcpy.ListFields(mapIndexTbl)

with arcpy.da.SearchCursor(mosaicD,'name') as cursorB:
        for rowB in cursorB:
            inputValues = []
            def fetch(entries):
                for entry in entries:
                    field = entry[0]
                    text  = entry[1].get()
                    inputValues.append(text)
                root.destroy()

            def makeform(root, fields):
                entries = []
                for field in fields:
                    row = Frame(root)
                    lab = Label(row, width=20, text=field, anchor='w')
                    ent = Entry(row)
                    row.pack(side=TOP, fill=X, padx=5, pady=5)
                    lab.pack(side=LEFT)
                    ent.pack(side=RIGHT, expand=YES, fill=X)
                    entries.append((field, ent))
                return entries

            if __name__ == '__main__':
                root = Tk()
                root.iconbitmap(r'\\sv04docifs5\data5\vol2\Records\GIS\Logos\CT.ico')
                root.geometry('375x650')
                root.wm_title('Enter values for '+rowB[0])
                cities = ('Toronto', 'Ottawa', 'Montreal', 'Vancouver', 'St. John')
                cblist = Frame(root)
                cbp3 = ttk.Labelframe(cblist, text='Pre-defined List')
                cb3 = ttk.Combobox(cbp3, values=cities, state='readonly')
                cb3.current(1)  # set selection
                cb3.pack(side=LEFT, expand=YES, fill=X)
                # position and display
                cbp3.pack(in_=cblist, side=TOP, pady=5, padx=10)
                ents = makeform(root, formFields)
                root.bind('<Return>', (lambda event, e=ents: fetch(e)))
                b1 = Button(root, text='Submit',
                      command=(lambda e=ents: fetch(e)))
                b1.pack(padx=5, pady=5,anchor=CENTER)
                #b2 = Button(root, text='Quit', command=root.quit)
                #b2.pack(side=LEFT, padx=5, pady=5)
                root.mainloop()

1 个答案:

答案 0 :(得分:1)

组合框cb3打包在框架cbp3中。该框架打包在框架cblist中。您无处在pack上致电gridcblist。由于cblist是不可见的,因此它的子女也是如此。