本文整理汇总了Python中tkinter.ttk.Treeview.parent方法的典型用法代码示例。如果您正苦于以下问题:Python Treeview.parent方法的具体用法?Python Treeview.parent怎么用?Python Treeview.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Treeview
的用法示例。
在下文中一共展示了Treeview.parent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ElementListWidget
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import parent [as 别名]
class ElementListWidget(Frame):
def __init__(self, parent, label, columns, showError):
Frame.__init__(self, parent)
self.showError = showError
self.columnconfigure(0, weight = 1)
self.rowconfigure(1, weight = 1)
# Название таблицы
self.titleLabel = Label(self, text = label)
self.titleLabel.grid(column = 0, row = 0, sticky = W + E)
# Таблица значений
columns = ("Метка", "№") + columns
self.tree = Treeview(self, columns = columns, displaycolumns = columns,
selectmode = "browse")
self.tree.grid(column = 0, row = 1, sticky = W + N + E + S)
# Настраиваем внешний вид таблицы (первые колонки)
self.tree.column("#0", width = 0, stretch = 0) # Прячем колонку с иконкой
self.tree.column( columns[0], anchor = W, width = 150)
self.tree.heading(columns[0], anchor = W, text = columns[0])
self.tree.column( columns[1], anchor = E, width = 80)
self.tree.heading(columns[1], anchor = E, text = columns[1])
self.tree.bind("<<TreeviewSelect>>", self.onSelectionChanged)
# Панель с кнопками
self.buttonPanel = Frame(self)
self.buttonPanel.grid(column = 0, row = 2, sticky = W + E)
self.buttonPanel.columnconfigure(0, weight = 1)
self.buttonPanel.columnconfigure(3, minsize = emptySpaceSize, weight = 0)
self.buttonPanel.columnconfigure(6, minsize = emptySpaceSize, weight = 0)
self.buttonPanel.columnconfigure(9, weight = 1)
# Кнопки добавления/удаления элемента
self.buttonAdd = Button(self.buttonPanel, text = "+", width = 3,
command = self.onButtonAddClicked)
self.buttonAdd.grid(column = 1, row = 0)
self.buttonRemove = Button(self.buttonPanel, text = "-", width = 3, state = DISABLED,
command = self.onButtonRemoveClicked)
self.buttonRemove.grid(column = 2, row = 0)
# Кнопки перемещения элемента
self.buttonUp = Button(self.buttonPanel, text = "↑", width = 3, state = DISABLED,
command = self.onButtonUpClicked)
self.buttonUp.grid(column = 4, row = 0)
self.buttonDown = Button(self.buttonPanel, text = "↓", width = 3, state = DISABLED,
command = self.onButtonDownClicked)
self.buttonDown.grid(column = 5, row = 0)
# Кнопки применить/отменить (для выбранного элемента)
self.buttonCancel = Button(self.buttonPanel, text = "✗", width = 3,
command = self.updateSelectedFrame)
self.buttonCancel.grid(column = 7, row = 0)
self.buttonApply = Button(self.buttonPanel, text = "✓", width = 3,
command = self.onButtonApplyClicked)
self.buttonApply.grid(column = 8, row = 0)
# Редактирование выделенного элемента
self.i = StringVar()
self.label = (StringVar(), StringVar())
self.selectedFrame = Frame(self)
self.selectedFrame.grid(column = 0, row = 3, sticky = W + E)
# Номер
Label(self.selectedFrame, text = "№:") \
.grid(column = 0, row = 0)
Label(self.selectedFrame, textvariable = self.i, width = 3, justify = RIGHT) \
.grid(column = 1, row = 0)
# Пустое пространство
self.selectedFrame.columnconfigure(2, minsize = emptySpaceSize, weight = 0)
# Метка
Entry(self.selectedFrame, textvariable = self.label[0]) \
.grid(column = 3, row = 0, sticky = W + E)
Entry(self.selectedFrame, textvariable = self.label[1], bg = defaultValueBG) \
.grid(column = 4, row = 0, sticky = W + E)
# Виджет для элементов классов-потомков
self.detailFrame = Frame(self.selectedFrame)
self.detailFrame.grid(column = 3, row = 1, columnspan = 2, sticky = W + N + E + S)
self.selectedFrame.columnconfigure(3, weight = 1)
self.selectedFrame.columnconfigure(4, weight = 1)
self.selectedFrame.rowconfigure(1, weight = 1)
#.........这里部分代码省略.........
示例2: fillTree
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import parent [as 别名]
class Window:
def fillTree(self,path, parent, list):
for file in os.listdir(path):
abspath = os.path.join(path,file)
color = ""
treelist = None
for mini in list:
if abspath in mini:
color = 'red'
treelist = mini
else:
for lk in mini:
if abspath in lk:
color = 'purple'
child = None
if color == 'red':
child = self.tree.insert(parent,'end',text=file,open=False,tags=(abspath,'red',str(treelist)),)
elif color == 'purple':
child = self.tree.insert(parent,'end',text=file,open=False,tags=(abspath,'purple'))
else:
child = self.tree.insert(parent,'end',text=file,open=False,tags=(abspath,'white'))
if(os.path.isdir(abspath)):
self.tree.insert(child,'end',text='',open=False)
def __init__(self,list,dirlist):
self.root = Tk()
self.root.wm_title("Duplicate_Files")
self.min = None
self.list = list
self.root.geometry('600x600+0+0')
self.tree = Treeview(self.root ,height=15)
self.tree.pack(expand='yes',fill='both')
self.tree.heading('#0',text="files")
self.tree.tag_configure('red',foreground='red')
self.tree.tag_configure('purple',foreground='#cc00ff')
self.tree.bind("<Double-1>",self.onDoubleClick)
self.tree.bind("<<TreeviewOpen>>",self.onOpen)
self.tree.bind("<<TreeviewClose>>",self.onClose)
for path in dirlist:
branch = self.tree.insert('','end',text=path,open=True,tags=(path,'white'))
self.fillTree(path,branch,list)
self.root.mainloop()
def onDoubleClick(self,event):
item = self.tree.selection()[0]
print ("clicked" + str(self.tree.item(item,'tags')[0]))
if str(self.tree.item(item,'tags')[1]) == "red":
list_of_files = ast.literal_eval(str(self.tree.item(item,'tags')[2]))
if self.min != None:
if self.min.mini.winfo_exists():
self.min.mini.destroy()
self.min = MiniWindow(self.root,list_of_files)
def onOpen(self,event):
item = self.tree.selection()[0]
if self.tree.parent(item) != '':
if len(self.tree.get_children(item))>0:
self.tree.delete(self.tree.get_children(item))
abspath = str(self.tree.item(item,'tags')[0])
if(os.path.isdir(abspath)):
self.fillTree(abspath, item,self.list)
def onClose(self,event):
item = self.tree.selection()[0]
if self.tree.parent(item) != '':
if len(self.tree.get_children(item))>0:
self.tree.delete(self.tree.get_children(item))