本文整理汇总了Python中ttk.Treeview.parent方法的典型用法代码示例。如果您正苦于以下问题:Python Treeview.parent方法的具体用法?Python Treeview.parent怎么用?Python Treeview.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ttk.Treeview
的用法示例。
在下文中一共展示了Treeview.parent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import parent [as 别名]
class Display:
def __init__(self, controller):
self.controller = controller
self.currIndex = 0
# initialize the GUI
self.app = Tk()
self.app.title('Jack Magee\'s Pub')
self.tree = Treeview(self.app, height=30)
# name the tree columns, not sure if they have to be named numbers but that's how the example did it
self.tree["columns"]=("one", "two", "three", "four")
# set the column widths
self.tree.column("one", width=200)
self.tree.column("two", width=300)
self.tree.column("three", width=200)
self.tree.column("four", width=200)
# set the column headings
self.tree.heading("#0", text= "ID")
self.tree.heading("one", text="Name")
self.tree.heading("two", text="Order")
self.tree.heading("three", text="Price")
self.tree.heading("four", text="Respond (double-click)")
self.tree.pack()
# register handler for double-clicks
self.tree.bind("<Double-1>", self.OnDoubleClick)
def mainloop(self):
self.app.mainloop()
# this is like making tree entries buttons
def OnDoubleClick(self, event):
# get the pressed item
item = self.tree.selection()[0]
# get the item's text
response = self.tree.item(item,"text")
# this is the only response we are sending for now
if response == 'rdy':
# get the parent directory whose text is the customer id
parent = self.tree.parent(item)
customer_id = self.tree.item(parent,"text")
# remove it from the tree
self.tree.delete(parent)
# send the message to the customer
self.controller.send_msg(customer_id, response)
# add a new order to the tree
def takeOrder(self, customer_id, name, order, price):
# just a row identifier
thisRow = str(self.currIndex)
# insert the i.d. and name at the top level
self.tree.insert("", self.currIndex, thisRow, text=customer_id, values=(name, "", "", ""))
# insert the "button" for sending notification to clients
self.tree.insert(thisRow, 0, text='rdy', values=("", "", "", "Ready For Pick Up"))
# this is a hacky solution to get multiline orders to appear because treeviews will
# crop anything more than 1 line so I just make a new entry for every line
multiline_order = order.split('\n')
this_line = 1
for line in multiline_order[:-1]: # exclude the last end line
if this_line == 1: # the first line has the name of the order and it's price
self.tree.insert(thisRow, 1, text="order",values=("", order, price, ""))
else: # just keep printing the extra options, sides, and add ons
self.tree.insert(thisRow, this_line, text="order",values=("", line, "", ""))
this_line += 1
self.currIndex += 1
示例2: pylasticGUI
# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import parent [as 别名]
#.........这里部分代码省略.........
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)
ysb.grid(in_=f, row=0, column=1, sticky=NS)
xsb.grid(in_=f, row=1, column=0, sticky=EW)
# set frame resizing priorities
f.rowconfigure(0, weight=1)
f.columnconfigure(0, weight=1)
# action to perform when a node is expanded
self.tree.bind('<<TreeviewOpen>>', self._update_tree)
self.tree.bind("<Double-1>", self.OnDoubleClick)