[英]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
. 您
cblist
在cblist
上调用pack
或grid
。 Since cblist
is invisible, so are its children. 由于
cblist
是不可见的,因此它的子cblist
也是不可见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.