本文整理汇总了Python中ttk.Treeview.get_children方法的典型用法代码示例。如果您正苦于以下问题:Python Treeview.get_children方法的具体用法?Python Treeview.get_children怎么用?Python Treeview.get_children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ttk.Treeview
的用法示例。
在下文中一共展示了Treeview.get_children方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Multicolumn_Listbox
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import get_children [as 别名]
#.........这里部分代码省略.........
if sort:
self.interior.heading(i, text=columns[i], anchor=heading_anchor, command=lambda col=i: self.sort_by(col, descending=False))
else:
self.interior.heading(i, text=columns[i], anchor=heading_anchor)
if adjust_heading_to_content:
self.interior.column(i, width=Font().measure(columns[i]))
self.interior.column(i, anchor=cell_anchor)
if data is not None:
for row in data:
self.insert_row(row)
@property
def row_height(self):
return self._rowheight
@property
def font(self):
return self._cell_font
def configure_column(self, index, width=None, minwidth=None, anchor=None, stretch=None):
kwargs = {}
for config_name in ("width", "anchor", "stretch", "minwidth"):
config_value = locals()[config_name]
if config_value is not None:
kwargs[config_name] = config_value
self.interior.column('#%s'%(index+1), **kwargs)
def row_data(self, index):
try:
item_ID = self.interior.get_children()[index]
except IndexError:
raise ValueError("Row index out of range: %d"%index)
return self.item_ID_to_row_data(item_ID)
def update_row(self, index, data):
try:
item_ID = self.interior.get_children()[index]
except IndexError:
raise ValueError("Row index out of range: %d"%index)
if len(data) == len(self._columns):
self.interior.item(item_ID, values=data)
else:
raise ValueError("The multicolumn listbox has only %d columns"%self._number_of_columns)
def delete_row(self, index):
list_of_items = self.interior.get_children()
try:
item_ID = list_of_items[index]
except IndexError:
raise ValueError("Row index out of range: %d"%index)
self.interior.delete(item_ID)
self._number_of_rows -= 1
if self._stripped_rows:
for i in range(index, self._number_of_rows):
self.interior.tag_configure(list_of_items[i+1], background=self._stripped_rows[i%2])
def insert_row(self, data, index=None):
示例2: WaitingRoom
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import get_children [as 别名]
class WaitingRoom(cll.ClientListener, object): #Note: extending cll.ClientListener if Gui does not extend WaitingRoom
def __init__(self):
self.Names = []
self.tree_headers = ['Player','Status','Address','Game','Color']
self.quit = False #quit program after wroom has been closed. it will be passed to Gui.quit
def startWaitingRoomUI(self, pumpit):
self.pumpit = True
if 'pumpit' in locals():
self.pumpit = pumpit
cfg.wroom = Tk()
cfg.wroom.protocol("WM_DELETE_WINDOW", self.quitWaitingRoom)
"""State variables - By using textvariable=var in definition widget is tied to this variable"""
statusmsg_sv = StringVar() #needed
entry_sv = StringVar(value = cfg.name)
#entry_sv.trace("w", lambda name, index, mode, sv=entry_sv: self.changeName(sv))
chatentry_sv = StringVar(value = "Press enter to chat")
"""Create and grid the outer content frame"""
content = ttk.Frame(cfg.wroom) #, padding=(5, 5, 12, 0)) #Frame in cfg.wroom
content.grid(column = 0, row = 0, sticky = (N,W,E,S))
cfg.wroom.grid_columnconfigure(0, weight = 1)
cfg.wroom.grid_rowconfigure(0, weight = 1)
"""Create the different widgets; note the variables that some widgets are bound to"""
self.tree = Treeview(content, show="headings", columns=cfg.wroominstance.tree_headers, name = "treeview")
self.tree.column("#1", minwidth = 100, width = 120, stretch = NO)
self.tree.column("#2", minwidth = 30, width = 60, stretch = NO)
self.tree.column("#3", minwidth = 30, width = 50, stretch = YES)
self.tree.column("#4", minwidth = 30, width = 50, stretch = YES)
self.tree.column("#5", minwidth = 30, width = 50, stretch = YES)
namelbl = ttk.Label(content, text="Player name")
self.nameentry = ttk.Entry(content, bg = 'white', textvariable = entry_sv, name = "nameentry")#, validatecommand=validateIt)
colorlbl = ttk.Label(content, text="Player color")
self.colorframe = ttk.Frame(content, name = "colorframe", borderwidth = 1, relief='sunken')
lbl = ttk.Label(content, text="Send to player:") #Label on the right
self.log = Listbox(content, height = 5, bg = 'white', name = "logbox")#, listvariable=cmessagelog #Listbox with messages
self.chatAll = ttk.Button(content, text = 'Chat to All', command = self.chatToAll, default = 'active', width = '6',name = "chat")
self.chatentry = ttk.Entry(content, bg = 'white', foreground = 'gray', textvariable = chatentry_sv, name = "chatentry", selectforeground = 'blue')
testbtn = ttk.Button(content, text = 'Connections', command = self.test, default = 'active', width = '6', name = "testbtn")
ready = ttk.Button(content, text = 'Ready', command = self.toggleReadyForGame, default = 'active', width = '6', name = "readybtn")
solitaire = ttk.Button(content, text = 'Solitaire', command = self.solitaire, default = 'active', width = '6', name = "solitairebtn")
quit = ttk.Button(content, text = 'Quit', command = self.quitWaitingRoom, default = 'active', width = '6', name = "quitbtn")
status = ttk.Label(content, textvariable = statusmsg_sv, anchor = W, name = "statuslbl") #Label on the bottom
def get_tree():
"""Get from the self.tree an item when clicked"""
idxs = self.tree.item(self.tree.focus())
vals = idxs['values']
if len(idxs['values'])==0: return None
return vals
"""def sortby(tree, col, descending):
Sort tree contents when a column header is clicked on
# grab values to sort
data = [(tree.set(child, col), child) \
for child in tree.get_children('')]
# now sort the data in place
data.sort(reverse=descending)
for ix, item in enumerate(data):
tree.move(item[1], '', ix)
# switch the heading so it will sort in the opposite direction
tree.heading(col, command=lambda col=col: sortby(tree, col, int(not descending)))
"""
def showstatus(*args):
"""Called when the selection in the listbox changes;
Update the status message on the bottom with the new information"""
list = get_tree()
if list is None:
return
statusmsg_sv.set("Player %s has this status: %s" % (list[0], list[1]))
# Grid all the widgets
self.tree.grid(row = 0, column = 0, rowspan = 9, sticky = (N,S,E,W))
namelbl.grid(row = 0, column = 1, columnspan = 2, sticky = (N,W), padx = 5)
self.nameentry.grid(row = 1, column = 1, columnspan = 2, sticky = (N,E,W), pady = 5, padx = 5)
colorlbl.grid(row = 0, column = 3, columnspan = 1, sticky = (N,W), padx = 5)
self.colorframe.grid(row = 1, column = 3, columnspan = 1, sticky = (N,E,W), pady = 5, padx = 5)
#testbtn.grid(row = 3, column = 3, columnspan = 1, sticky = E, padx = 5) #Test Button
self.log.grid(row = 5, column = 1, columnspan = 3, sticky = (N,S,E,W), padx = 5, pady = 5) #Listbox with all messages
self.chatentry.grid(row = 6, column = 1, columnspan = 2, sticky = (N,E), padx = 5, pady = 5)
self.chatAll.grid(row = 6, column = 3, columnspan = 1, sticky = (N,E), padx = 5, pady = 5)
ready.grid(row = 7, column = 1, sticky = (W,S), padx = 5, pady = 5) #
solitaire.grid(row = 7, column = 2, sticky = (W,S), padx = 5, pady = 5)
quit.grid(row = 7, column = 3, sticky = (W,S), padx = 5, pady = 5)
status.grid(row = 9, column = 0, columnspan = 2, sticky = (W,E))
"""Configure content Frame and color Frame"""
content.grid_columnconfigure(0, weight = 1)
content.grid_rowconfigure(5, weight = 1)
h = self.nameentry.winfo_reqheight()
self.colorframe.configure(height = h, bg = 'red')
"""Set event bindings"""
self.tree.bind('<<TreeviewSelect>>', showstatus)
self.nameentry.bind('<Return>', (lambda _: self.askChangeName(self.nameentry)))
self.nameentry.bind('<FocusOut>', (lambda _: self.askChangeName(self.nameentry)))
cfg.wroom.bind('<Control-Key-w>', self.quitWaitingRoom)
cfg.wroom.bind('<Control-Key-q>', self.quitWaitingRoom)
cfg.wroom.bind('<Control-Key-r>', self.toggleReadyForGame)
#.........这里部分代码省略.........
示例3: XML_Viwer
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import get_children [as 别名]
class XML_Viwer(Frame):
def __init__(self, master, xml=None, heading_text=None, heading_anchor=None, padding=None, cursor=None, takefocus=None, style=None):
Frame.__init__(self, master, class_="XML_Viwer")
self._vsb = Scrollbar(self, orient=VERTICAL)
self._hsb = Scrollbar(self, orient=HORIZONTAL)
kwargs = {}
kwargs["yscrollcommand"] = lambda f, l: autoscroll(self._vsb, f, l)
kwargs["xscrollcommand"] = lambda f, l: autoscroll(self._hsb, f, l)
if style is not None:
kwargs["style"] = style
if padding is not None:
kwargs["padding"] = padding
if cursor is not None:
kwargs["cursor"] = cursor
if takefocus is not None:
kwargs["takefocus"] = takefocus
self._treeview = Treeview(self, **kwargs)
if heading_text is not None:
if heading_anchor is not None:
self._treeview.heading("#0", text=heading_text, anchor=heading_anchor)
else:
self._treeview.heading("#0", text=heading_text)
self._treeview.bind("<<TreeviewOpen>>", self._on_open)
self._treeview.bind("<<TreeviewClose>>", self._on_close)
# Without this line, horizontal scrolling doesn't work properly.
self._treeview.column("#0", stretch= False)
self._vsb['command'] = self._treeview.yview
self._hsb['command'] = self._treeview.xview
self._treeview.grid(column=0, row=0, sticky=N+S+W+E)
self._vsb.grid(column=1, row=0, sticky=N+S)
self._hsb.grid(column=0, row=1, sticky=E+W)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self._element_tree = None
self._item_ID_to_element = {}
if xml is not None:
self.parse_xml(xml)
def _on_open(self, event):
item_ID = self._treeview.focus()
if item_ID not in self._item_ID_to_element: return
node = self._item_ID_to_element[item_ID]
self._treeview.item(item_ID, text = self._repr_of_openning_tag(node))
def _on_close(self, event):
item_ID = self._treeview.focus()
if item_ID not in self._item_ID_to_element: return
node = self._item_ID_to_element[item_ID]
text = self._repr_of_openning_tag(node) + self._repr_of_closing_tag(node)
self._treeview.item(item_ID, text = text)
def parse_xml(self, xml):
self._element_tree = ET.ElementTree(ET.fromstring(xml))
self.clear()
self._walk_xml(self._element_tree.getroot())
@property
def element_tree(self):
return self._element_tree
@element_tree.setter
def element_tree(self, element_tree):
self._element_tree = element_tree
self.clear()
self._walk_xml(element_tree.getroot())
def clear(self):
self._item_ID_to_element = {}
self._treeview.delete(*self._treeview.get_children())
def _repr_of_openning_tag(self, node):
text = "<" + node.tag
attrs = node.attrib
# list function is here necessary to provide support to Python 3
a_names = list(attrs.keys())
a_names.sort()
#.........这里部分代码省略.........
示例4: CommSearch
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import get_children [as 别名]
class CommSearch(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.entries_found = []
self.parent.title("Search your command cards")
self.style = Style()
self.style.theme_use("default")
self.pack()
self.input_title = Label(self, text="Enter your command below")
self.input_title.grid(row=0, columnspan=2)
self.input_box = Entry(self, width=90)
self.input_box.grid(row=1, column=0)
self.input_box.focus()
self.input_box.bind("<Key>", self.onUpdateSearch)
self.search_btn = Button(self, text="Search", command=self.onSearch)
self.search_btn.grid(row=1, column=1)
self.output_box = Treeview(self, columns=("Example"))
ysb = Scrollbar(self, orient='vertical', command=self.output_box.yview)
xsb = Scrollbar(self, orient='horizontal', command=self.output_box.xview)
self.output_box.configure(yscroll=ysb.set, xscroll=xsb.set)
self.output_box.heading('Example', text='Example', anchor='w')
self.output_box.column("#0",minwidth=0,width=0, stretch=NO)
self.output_box.column("Example",minwidth=0,width=785)
self.output_box.bind("<Button-1>", self.OnEntryClick)
self.output_box.grid(row=3, columnspan=2)
self.selected_box = Text(self, width=110, height=19)
self.selected_box.grid(row=4, columnspan=2)
self.gotoadd_btn = Button(self, text="Go to Add", command=self.onGoToAdd)
self.gotoadd_btn.grid(row=5)
def OnEntryClick(self, event):
try:
item = self.output_box.selection()[0]
except IndexError:
pass
entry_title = self.output_box.item(item,"value")
for item in self.entries_found:
if str(entry_title) == str("('" + item.title.strip('\n') + "',)"):
self.selected_box.delete(0.1, END)
self.selected_box.insert(END, item.text + '\n')
def onUpdateSearch(self, key):
# Somehow calling self.onSearch() does not register last key
# And we need to correct "special chars"
global entries, entries_map
text_entries = ""
for item in self.output_box.get_children():
self.output_box.delete(item)
# ...like, for instance, deleting last character
if key.char == '\b':
search_terms = str(self.input_box.get()[:-1])
else:
search_terms = str(self.input_box.get() + key.char)
self.entries_found = []
self.entries_found = data.Search(search_terms,entries,entries_map)
for item in range(len(self.entries_found)):
aux = self.output_box.insert('', 'end', '', value=[self.entries_found[item].title.split('\n')[0]])
def onSearch(self):
global entries, entries_map
text_entries = ""
for item in self.output_box.get_children():
self.output_box.delete(item)
search_terms = str(self.input_box.get())
for item in data.Search(search_terms,entries,entries_map):
self.output_box.insert('', 'end', '', value=[self.entries_found[item].title.split('\n')[0]])
def onGoToAdd(self):
newroot = Tk()
newcomm = CommAdd(newroot)
newroot.geometry("800x600+0+0")
newroot.mainloop()
示例5: ProjectVenster
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import get_children [as 别名]
class ProjectVenster (ZoekVenster):
TITLE = 'Projecten'
def fill(self):
super(self.__class__, self).fill()
#Basisvelden
self.identry = EntryField(self.veldenFrame, 'Projectnummer', row=0)
self.naamentry = EntryField(self.veldenFrame, 'Projectnaam', row=1)
self.jaarentry = EntryField(self.veldenFrame, 'Jaar', row=2)
self.budgetentry = EntryField(self.veldenFrame, 'Budget', row=3)
self.keywordLabel = Label(self.veldenFrame, text='Trefwoorden:')
self.keywordLabel.grid(row=4, column=0, sticky=W)
self.keywordText = Text(self.veldenFrame, relief=SUNKEN, wrap=WORD, width=60, height=3)
self.keywordText.grid(row=4, column=1, sticky=W)
#Partners
self.partnersLabel = Label(self.veldenFrame, text='Relaties:')
self.partnersLabel.grid(row=5, column=0)
self.partnersFrame = Frame(self.veldenFrame)
self.partnersFrame.grid(row=5, column=1, sticky=W+E)
self.partnersListBox = Treeview(self.partnersFrame, columns=('Relatie', 'Rol'), height=3, show='headings', selectmode=BROWSE)
self.partnersListBox.grid(row=0, column=0, sticky=W+E)
self.partnersKnopFrame = Frame(self.veldenFrame)
self.partnersKnopFrame.grid(row=6, column=1, sticky=E)
self.pScrollbar = Scrollbar(self.partnersFrame)
self.pScrollbar.grid(row=0, column=1, sticky=N+S+E)
self.partnersListBox.config(yscrollcommand=self.pScrollbar.set)
self.pScrollbar.config(command=self.partnersListBox.yview)
self.partnersToevoegenKnop = Button(self.partnersKnopFrame, text='Toevoegen...', command=self.partnerToevoegen)
self.partnersToevoegenKnop.grid()
self.partnersVerwijderenKnop = Button (self.partnersKnopFrame, text='Verwijderen', command=self.partnerVerwijderen)
self.partnersVerwijderenKnop.grid(row=0, column=1)
self.partnersListBox.bind('<<TreeviewSelect>>', self.nieuwePartnerSelectie)
#Bestanden
self.bestandenHoofdFrame = Frame(self.resultaatframe)
self.bestandenHoofdFrame.grid(row=2)
self.bestandenLabel = Label(self.bestandenHoofdFrame, text='Bestanden:')
self.bestandenLabel.grid(row=7, column=0, sticky=W)
self.bestandenFrame = Frame(self.bestandenHoofdFrame)
self.bestandenFrame.grid(row=7, column=1, sticky=W+E)
self.bestandenListBox = Listbox(self.bestandenFrame, selectmode=EXTENDED, width=50, height=10)
self.bestandenListBox.grid(row=0, column=0, sticky=W+E)
self.bScrollbar = Scrollbar(self.bestandenFrame)
self.bScrollbar.grid(row=0, column=1, sticky=N+S+E)
self.bestandenListBox.config(yscrollcommand=self.bScrollbar.set)
self.bScrollbar.config(command=self.bestandenListBox.yview)
self.bestandenKnopFrame = Frame(self.bestandenHoofdFrame)
self.bestandenKnopFrame.grid(row=8, column=1, sticky=E)
self.bestandenToevoegKnop = Button(self.bestandenKnopFrame, text='Bestanden toevoegen...', command=self.bestandenToevoegen)
self.bestandenToevoegKnop.grid(row=0, column=0, sticky=E)
self.mapToevoegenKnop = Button(self.bestandenKnopFrame, text='Map toevoegen...', command=self.mapToevoegen)
self.mapToevoegenKnop.grid(row=0, column=1, sticky=E)
self.bestandenOphaalKnop = Button(self.bestandenKnopFrame, text='Ophalen...', command=self.bestandenOphalen)
self.bestandenOphaalKnop.grid(row=0, column=2, sticky=E)
self.bestandenVerwijderKnop = Button(self.bestandenKnopFrame, text='Verwijderen', command=self.bestandenVerwijderen)
self.bestandenVerwijderKnop.grid(row=0, column=3, sticky=E)
self.pollBestandenLijst()
self.curid=-1
def disableResultaat(self):
self.identry.label.config(state=DISABLED)
self.identry.entry.config(state=DISABLED)
self.identry.setValue('')
self.naamentry.label.config(state=DISABLED)
self.naamentry.entry.config(state=DISABLED)
self.naamentry.setValue('')
self.jaarentry.label.config(state=DISABLED)
self.jaarentry.entry.config(state=DISABLED)
self.jaarentry.setValue('')
self.budgetentry.label.config(state=DISABLED)
self.budgetentry.entry.config(state=DISABLED)
self.budgetentry.setValue('')
self.keywordLabel.config(state=DISABLED)
self.keywordText.delete(1.0, END)
self.keywordText.config(state=DISABLED)
self.partnersLabel.config(state=DISABLED)
self.partnersListBox.delete(*self.partnersListBox.get_children())
self.partnersToevoegenKnop.config(state=DISABLED)
self.partnersVerwijderenKnop.config(state=DISABLED)
self.bestandenLabel.config(state=DISABLED)
self.bestandenListBox.delete(0, END)
self.bestandenListBox.config(state=DISABLED)
self.bestandenToevoegKnop.config(state=DISABLED)
self.mapToevoegenKnop.config(state=DISABLED)
self.bestandenOphaalKnop.config(state=DISABLED)
self.bestandenVerwijderKnop.config(state=DISABLED)
def enableResultaat(self):
self.identry.label.config(state=NORMAL)
self.identry.entry.config(state=NORMAL)
self.naamentry.label.config(state=NORMAL)
self.naamentry.entry.config(state=NORMAL)
self.jaarentry.label.config(state=NORMAL)
self.jaarentry.entry.config(state=NORMAL)
#.........这里部分代码省略.........
示例6: pylasticGUI
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import get_children [as 别名]
#.........这里部分代码省略.........
#self._populate_tree(root)
#
b1 = Button(frame, text="Refresh", width=15, command=lambda: self._populate_tree(root))
b1.grid(row=2, column=0)
b2 = Button(frame, text="Analyze", width=15, command=lambda: self.analyze(frame))
b2.grid(row=2, column=1)
b2 = Button(frame, text="Result", width=15, command=lambda: self.create_window())
b2.grid(row=2, column=2)
if self.__status and '--------' in self.__status: self.__finished = False
else: self.__finished = True
if self.__status and self.__finished:
ECs.set_analytics()
nb.add(frame, text='Analyze', underline=0, padding=2)
return
def _populate_tree(self, root, lock=None):
if lock: lock.acquire()
if len(self.tree.get_children(self.tree.get_children())) > 1:
for i in self.tree.get_children(self.tree.get_children()): self.tree.delete(i)
#self.tree.delete(self.tree.get_children())
status, paths = self.check_calc()
for key in status.keys():
#print paths[key].lstrip(self.__workdir).split('/')
self.tree.insert(root, END, text = status[key], values=['text3','text4', paths[key]])
if lock: lock.release()
def _create_treeview(self, parent):
f = Frame(parent)
#f.pack(side=TOP, fill=BOTH, expand=Y)
f.grid(row=0, column=0, sticky=NSEW, columnspan=3)
# create the tree and scrollbars
self.dataCols = ('fullpath', 'type', 'status')
self.tree = Treeview(columns=self.dataCols,
displaycolumns='status')
ysb = Scrollbar(orient=VERTICAL, command= self.tree.yview)
xsb = Scrollbar(orient=HORIZONTAL, command= self.tree.xview)
self.tree['yscroll'] = ysb.set
self.tree['xscroll'] = xsb.set
# setup column headings
self.tree.heading('#0', text='Directory Structure', anchor=W)
self.tree.heading('status', text='Status', anchor=W)
self.tree.column('status', stretch=0, width=100)
# add tree and scrollbars to frame
self.tree.grid(in_=f, row=0, column=0, sticky=NSEW)