简体   繁体   English

如何将tkinter组合框窗口小部件添加到还具有文本输入窗口小部件的gui中?

[英]How can I add a tkinter combobox widget to a gui that also has text entry widgets?

I am developing a gui with text entry widgets that regenerate based on the number of a records in a table. 我正在开发一个带有文本输入小部件的gui,该小部件可根据表中的记录数重新生成。 I am using a list of fields that are each created as an entry widget. 我正在使用字段列表,每个字段都被创建为条目小部件。 For at least one of these fields, I want to set up a combobox with values for the user to choose from. 对于这些字段中的至少一个,我想设置一个组合框,其中包含供用户选择的值。 I've been playing around with adding a combobox to the root (I've just inserted a sample one for now) but it doesn't show up when I run the script. 我一直在向根添加一个组合框(我现在刚刚插入了一个示例框),但是在运行脚本时它没有显示。 I don't get an error, the gui shows up with all the entry boxes, but not the combobox. 我没有收到错误,gui显示了所有输入框,但没有组合框。 Does anyone have any ideas: Here is some of the code: 是否有人有任何想法:这是一些代码:

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()

The combobox cb3 is packed in the frame cbp3 . 组合框cb3包装在框架cbp3 That frame is packed in frame cblist . 该框架包装在cblist框架中。 Nowhere do you call pack or grid on cblist . cblistcblist上调用packgrid Since cblist is invisible, so are its children. 由于cblist是不可见的,因此它的子cblist也是不可见的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tkinter - 如何删除 ComboBox 小部件中的粗体文本和焦点? - Tkinter - How can I delete the bold text and the focus in the ComboBox widgets? 如何将 tkinter 中 Entry 小部件的结果文本斜体化? - How can I italicize the resulting text from an Entry widget in tkinter? 如何使用 Tkinter 应用程序只保存填写的条目小部件而不将空的条目小部件保存在文本文件中? - How Can I only save filled in entry widgets without saving the empty entry widget in atext file using Tkinter app? 如何向 tkinter Text() 小部件添加超链接? - How can I add hyperlinks to a tkinter Text() widget? 我如何销毁多个条目窗口小部件Tkinter Python - How can I destroy multiple entry widgets tkinter python Tkinter:如何隐藏文本,就像使用带有文本(而非输入)小部件的密码一样? - Tkinter: How do I hide text as if with a password with a Text (not Entry) widget? Python Tkinter GUI:将文​​本从弹出窗口中的条目小部件添加到其他窗口中的列表框? - Python Tkinter GUI:add text from an entry widget in a pop up window to a listbox in a different window? Tkinter GUI –如何使用按钮删除一行Entry小部件 - Tkinter GUI – How to remove a row of Entry widgets, using a Button 如何使用绑定密钥 select tkinter 条目小部件? - How can I select tkinter entry widget with binded key? 如何更新 tkinter 中顶级 window 中的条目小部件条目? - How can I update entry widget entries in a toplevel window in tkinter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM