本文整理汇总了Python中tkinter.ttk.Treeview.item方法的典型用法代码示例。如果您正苦于以下问题:Python Treeview.item方法的具体用法?Python Treeview.item怎么用?Python Treeview.item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Treeview
的用法示例。
在下文中一共展示了Treeview.item方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BioInfo
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import item [as 别名]
#.........这里部分代码省略.........
# (List B and No List) or (No List and List B)
elif ((self.list1 is not None and self.typeList1 == ListBioType.TypeB) and (self.list2 is None)) or\
((self.list2 is not None and self.typeList2 == ListBioType.TypeB) and (self.list1 is None)):
self.resetTree()
try:
listComp = ListComparator(self.list1, self.list2, self.entryPVal.get(), self.entryFoldC.get())
for e in listComp.getFilterListB():
self.tree.insert('', 'end', values=e)
except IndexError:
showerror("Erreur : liste A invalide", "Le fichier liste A n'est pas un fichier valide")
# (List A and List B) or (List B and List A)
elif ((self.list1 is not None and self.typeList1 == ListBioType.TypeA) and \
(self.list2 is not None and self.typeList2 == ListBioType.TypeB)) or \
((self.list1 is not None and self.typeList1 == ListBioType.TypeB) and \
(self.list2 is not None and self.typeList2 == ListBioType.TypeA)):
self.resetTree()
listA = ""
listB = ""
if self.typeList1 == ListBioType.TypeA:
listA = self.list1
else:
listA = self.list2
if self.typeList1 == ListBioType.TypeB:
listB = self.list1
else:
listB = self.list2
try:
listComp = ListComparator(listA, listB, self.entryPVal.get(), self.entryFoldC.get(), self.entryNote.get())
for e in listComp.getDiffAandB():
self.tree.insert('', 'end', values=e)
except IndexError:
showerror("Erreur : liste A ou B invalide", "Le fichier liste A ou B n'est pas un fichier valide")
# (List A and List A)
elif ((self.list1 is not None and self.typeList1 == ListBioType.TypeA) and \
(self.list2 is not None and self.typeList2 == ListBioType.TypeA)):
self.resetTree()
try:
listComp = ListComparator(self.list1, self.list2, self.entryPVal.get(), self.entryFoldC.get(), self.entryNote.get())
for e in listComp.getDiffAandA():
self.tree.insert('', 'end', values=e)
except IndexError:
showerror("Erreur : liste A ou B invalide", "Le fichier liste A ou B n'est pas un fichier valide")
# (List B and List B)
elif ((self.list1 is not None and self.typeList1 == ListBioType.TypeB) and \
(self.list2 is not None and self.typeList2 == ListBioType.TypeB)):
self.resetTree()
try:
listComp = ListComparator(self.list1, self.list2, self.entryPVal.get(), self.entryFoldC.get())
for e in listComp.getDiffBandB():
self.tree.insert('', 'end', values=e)
except IndexError:
showerror("Erreur : liste A ou B invalide", "Le fichier liste A ou B n'est pas un fichier valide")
else:
showerror("Erreur : Combinaisons de listes invalides", "Votre choix de types de listes ne correspond à aucune combinaison possible, contacter le developpeur")
def export(self):
if len(self.tree.get_children()) == 0:
showinfo("Export", "Il n'y a rien à exporter")
return
fname = asksaveasfilename(filetypes=(("CSV files", "*.csv"),
("All files", "*.*") ))
if fname:
resExp = []
for it in self.tree.get_children():
resExp.append(self.tree.item(it)["values"])
expTabToCSV = TreeExportator(resExp, fname)
expTabToCSV.export()
showinfo("Export", "Exportation au format CSV réussi")
def columnSort (self, col, descending=False):
data = [(self.tree.set(child, col), child) for child in self.tree.get_children('')]
data.sort(reverse=descending)
for indx, item in enumerate(data):
self.tree.move(item[1], '', indx)
# reverse sort direction for next sort operation
self.SortDir = not descending
示例2: Tree
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import item [as 别名]
class Tree(LibraryListener):
def __init__(self, config, master):
self.views = config['views']
self.library = None
self.__make_widgets(master)
def __make_widgets(self, root):
self.tree = Treeview(root)
def on_library_change(self, library):
self.library = library
self.__make_root_nodes()
def __make_root_nodes(self):
for i in self.tree.get_children():
self.tree.delete(i)
root_nodes = self.query_library({}, self.views[0])
for node in root_nodes:
child = self.tree.insert("", "end", self.__make_node_id(None, self.views[0], node), text=node,
tags=self.views[0])
self.fetch_children(child)
@staticmethod
def __make_node_id(parent_node, node_type, node_value):
node_id = {}
if parent_node:
node_id = copy(parent_node)
node_id[node_type] = node_value
return node_id
def can_be_expanded(self, node_type):
return node_type != self.views[len(self.views) - 1]
def get_child_node_type(self, node_type):
return self.views[self.views.index(node_type) + 1]
def query_library(self, node_id, view):
return self.library.aggregate(node_id, view)
def __has_children(self, node):
return len(self.children(node)) > 0
def fetch_children(self, node):
if not self.__has_children(node):
node_type = self.tree.item(node, "tags")[0]
if self.can_be_expanded(node_type):
children_node_type = self.get_child_node_type(node_type)
node_id = literal_eval(node)
nodes = self.query_library(node_id, children_node_type)
for child_node in nodes:
self.tree.insert(node, "end", self.__make_node_id(node_id, children_node_type, child_node),
text=child_node, tags=children_node_type)
def delete_children(self, parent_node):
children = self.children(parent_node)
for node in children:
self.tree.delete(node)
@property
def selected_node(self):
if len(self.tree.selection()):
return self.tree.selection()[0]
def children(self, node):
return self.tree.get_children(node)
示例3: Expenses
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import item [as 别名]
class Expenses(Frame):
# Creates the first option menus in the expense window
def createOptionButtons(self):
self.master.title("Expenses")
# Creates the add item to inventory button
addItem = Button(root, text="Add item to inventory", command=lambda: self.sequence(self.addItem))#addItem(master))) # This button will send to the user to the add item page
addItem.place(x = 130, y = 100)
# Creates the view items in inventory button
inventoryButton = Button(root, text="View items in inventory", command=lambda: self.sequence(self.viewInveroty)) # This button will send the user to the view inventory page
inventoryButton.place(x = 130, y = 150)
# Create the total cost button
totalCost = Button(root, text="Total Cost", command=lambda: self.sequence(self.viewTotalCost))
totalCost.place(x = 130, y = 200)
# Creates the back button
backButton = Button(root, text="Back", command=returnHome) # This button will return the user to the main page. Still working on it.
backButton.place(x = 50, y = 350)
# Creates the add item to inventory button and entries
def addItem(self):
self.master.title("Add new item") # Changes the title of the page to Add New Item
# Creates a label called nameOfItems and an entry called itemName
nameOfItem = Label(root, text="Item Name: ")
nameOfItem.place(x = 110, y = 100)
self.itemName = Entry(root) # This will allow the user to enter the name of the item that they will be adding
self.itemName.place(x = 190, y = 100)
# Creates the label called itemTypeLabel and a drop down menu called itemTypeChoice
itemTypeLabel = Label(root, text = "Item's type: ")
itemTypeLabel.place(x = 110, y = 160)
self.itemTypeChoice = StringVar(root) # This makes itemTypeChoice a permanent String
self.itemTypeChoice.set("Tree") # Tree is set to the default string of itemTypeChoice
typeChoices = OptionMenu(root, self.itemTypeChoice, "Tree", "Animal", "Machine") # Drop down menu is created and options Tree, Animal, and Machine are added to the menu
typeChoices.place(x = 190, y = 160)
backButton = Button(root, text = "Back", command=lambda: self.sequence(self.createOptionButtons))
backButton.place(x = 50, y = 350)
# Next button
nextButton = Button(root, text = "Next", command=self.saveNameAndType) #This button will send the user to the add inventory page
nextButton.place(x = 350, y = 350)
# Function that creates a new item object and assigns it a name and the type
def saveNameAndType(self):
name = self.itemName.get()
self.item = Inventory(name)
itemType = self.itemTypeChoice.get()
self.item.itemType = itemType
self.sequence(self.addToInventory)
# Creates the add to inventory options
def addToInventory(self):
self.master.title("Add %s to %s inventory" % (self.item.name, self.item.itemType))
# This assigns the variables month, day, and year to be value holder for integer values
# They are also set to be values of the class expenses (by using self) so that they can
# be used in the function updateDay and SaveDate
self.month = IntVar(self)
self.day = IntVar(self)
self.year = IntVar(self)
# This trace function is used to keep track of when the selected months and years change. This is
# done to adjust the days of the month according to the month or the year
self.month.trace('w', self.updateDay)
self.year.trace('w', self.updateDay)
numMonths = self.nums(1, 12) # Runs the nums function that creates a list from 1 to 12
numYears = self.nums(2015, 2030) # Runs the nums function that creates a list from 2015 to 2030
# This creates the drop down menu and assigns the options is the menu. The day menu is left empty and
# is assigned in the updateDay function
self.optionmenu_month = OptionMenu(root, self.month, *numMonths)
self.optionmenu_day = OptionMenu(root, self.day, '')
self.optionmenu_year = OptionMenu(root, self.year, *numYears)
# Sets the default value of the month and year options to 1 and 2015 respectively
self.month.set(numMonths[0])
self.year.set(numYears[0])
self.optionmenu_month.place(x = 100, y = 120)
self.optionmenu_day.place(x = 150, y = 120)
self.optionmenu_year.place(x = 200, y = 120)
datePurchased = Label(root, text = "Date Purchased")
datePurchased.place(x = 150, y = 95)
quantityPurchasedLabel = Label(root, text="Amount purchased:")
quantityPurchasedLabel.place(x = 50, y = 180)
self.quantityPurchasedEntry = Entry(root, bd=5) # Creates input box for user to insert the amount of items purchased
self.quantityPurchasedEntry.place(x = 180, y = 180)
pricePaidLabe = Label(root, text="Price paid for all: ")
pricePaidLabe.place(x = 50, y = 210)
self.pricePaidEntry = Entry(root, bd=5) # Creates input box for user to insert the price paid for the item
#.........这里部分代码省略.........
示例4: fillTree
# 需要导入模块: from tkinter.ttk import Treeview [as 别名]
# 或者: from tkinter.ttk.Treeview import item [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))