当前位置: 首页>>代码示例>>Python>>正文


Python Treeview.selection方法代码示例

本文整理汇总了Python中ttk.Treeview.selection方法的典型用法代码示例。如果您正苦于以下问题:Python Treeview.selection方法的具体用法?Python Treeview.selection怎么用?Python Treeview.selection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ttk.Treeview的用法示例。


在下文中一共展示了Treeview.selection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import selection [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
开发者ID:dnav6987,项目名称:PubApp,代码行数:77,代码来源:GUI.py

示例2: Multicolumn_Listbox

# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import selection [as 别名]
class Multicolumn_Listbox(object):
    _style_index = 0

    class List_Of_Rows(object):
        def __init__(self, multicolumn_listbox):
            self._multicolumn_listbox = multicolumn_listbox

        def data(self, index):
            return self._multicolumn_listbox.row_data(index)
            
        def get(self, index):
            return Row(self._multicolumn_listbox, index)

        def insert(self, data, index=None):
            self._multicolumn_listbox.insert_row(data, index)

        def delete(self, index):
            self._multicolumn_listbox.delete_row(index)

        def update(self, index, data):
            self._multicolumn_listbox.update_row(index, data)

        def select(self, index):
            self._multicolumn_listbox.select_row(index)

        def deselect(self, index):
            self._multicolumn_listbox.deselect_row(index)

        def set_selection(self, indices):
            self._multicolumn_listbox.set_selection(indices)

        def __getitem__(self, index): 
            return self.get(index)

        def __setitem__(self, index, value): 
            return self._multicolumn_listbox.update_row(index, value)

        def __delitem__(self, index): 
            self._multicolumn_listbox.delete_row(index)

        def __len__(self): 
            return self._multicolumn_listbox.number_of_rows

    class List_Of_Columns(object):
        def __init__(self, multicolumn_listbox):
            self._multicolumn_listbox = multicolumn_listbox
        
        def data(self, index):
            return self._multicolumn_listbox.get_column(index)

        def get(self, index):
            return Column(self._multicolumn_listbox, index)

        def delete(self, index):
            self._multicolumn_listbox.delete_column(index)

        def update(self, index, data):
            self._multicolumn_listbox.update_column(index, data)

        def __getitem__(self, index): 
            return self.get(index)

        def __setitem__(self, index, value): 
            return self._multicolumn_listbox.update_column(index, value)

        def __delitem__(self, index): 
            self._multicolumn_listbox.delete_column(index)

        def __len__(self): 
            return self._multicolumn_listbox.number_of_columns

    def __init__(self, master, columns, data=None, command=None, sort=True, select_mode=None, heading_anchor = CENTER, cell_anchor=W, style=None, height=None, padding=None, adjust_heading_to_content=False, stripped_rows=None, selection_background=None, selection_foreground=None, field_background=None, heading_font= None, heading_background=None, heading_foreground=None, cell_pady=2, cell_background=None, cell_foreground=None, cell_font=None, headers=True):

        self._stripped_rows = stripped_rows

        self._columns = columns
        
        self._number_of_rows = 0
        self._number_of_columns = len(columns)
        
        self.row = self.List_Of_Rows(self)
        self.column = self.List_Of_Columns(self)
        
        s = Style()

        if style is None:
            style_name = "Multicolumn_Listbox%s.Treeview"%self._style_index
            self._style_index += 1
        else:
            style_name = style
        
        style_map = {}
        if selection_background is not None:
            style_map["background"] = [('selected', selection_background)]
            
        if selection_foreground is not None:
            style_map["foeground"] = [('selected', selection_foreground)]

        if style_map:
            s.map(style_name, **style_map)
#.........这里部分代码省略.........
开发者ID:jacob-carrier,项目名称:code,代码行数:103,代码来源:recipe-580746.py

示例3: __init__

# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import selection [as 别名]

#.........这里部分代码省略.........
		l = Label(ef, text="File:", justify=LEFT)
		l.pack(side=LEFT)

		self.entry = Entry(ef, width=12)
		self.entry.pack(side=LEFT)
		fn = 'untitled.g'
		if self.app.GCodeFile:
			fn = os.path.basename(self.app.GCodeFile)
			if len(fn) > 8:
				fn = fn[0:8]
			fn += ".g"
		self.entry.delete(0, END)
		self.entry.insert(0, fn)
		ef.pack()
		
		self.bUpload = Button(blf, text="Upload", command=self.doUpload, width=6)
		self.bUpload.pack()

		blf.pack(fill='x')
		
		if self.app.printing or self.app.sdprinting:
			self.bPrint.config(state=DISABLED)
			self.bUpload.config(state=DISABLED)
			
		if not self.app.GCodeFile:
			self.bUpload.config(state=DISABLED)
			
		blf = Frame(bf)
		self.bExit = Button(blf, text='Exit', command=self.doExit, width=6) 
		self.bExit.pack()
		blf.pack()

		if self.startFile:
			self.tree.selection_set(self.startFile)
			
		self.top.geometry("360x300+100+100")

	def delTop(self):
		self.top.destroy()
		self.top = None
	
	def treeSelect(self, *arg):
		s = self.tree.selection()[0]
		
		try:
			d = s.split(':')[0]
		except:
			d = ""
			
		if len(d) == 0:
			d = '(root)'
			
		self.upDir.config(text="Dir: " + d)
		
		if self.app.printing or self.app.sdprinting or not self.app.GCodeFile:
			self.bUpload.config(state=DISABLED)
		else:
			self.bUpload.config(state=NORMAL)
			
		if ':' in s: # a file is chosen
			if self.app.printing or self.app.sdprinting:
				self.bPrint.config(state=DISABLED)
			else:
				self.bPrint.config(state=NORMAL)
			self.bDelete.config(state=NORMAL)
			
开发者ID:jbernardis,项目名称:repraphost,代码行数:69,代码来源:sdcard.py

示例4: CommSearch

# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import selection [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()
开发者ID:angelalonso,项目名称:comm,代码行数:84,代码来源:comm.py

示例5: GUIBuscador

# 需要导入模块: from ttk import Treeview [as 别名]
# 或者: from ttk.Treeview import selection [as 别名]
class GUIBuscador(Tk):

	def __init__(self, master = None):
		Tk.__init__(self, master)
		self.gui(master)
		self.dir = 'D:\Talker\Talker\Biblia'
		self.direc = glob("%s\*" % self.dir)

	def gui(self, master):
		self.frm = Frame(master)
		self.frm.pack(side = LEFT, expand = YES, fill = BOTH)
		self.left_side(self.frm)

		self.frm = Frame(master)
		self.frm.pack(side = RIGHT, expand = YES, fill = BOTH)
		self.right_side(self.frm)

	def left_side(self, master):
		self.nombre = Entry(master, justify = CENTER, bd = 3, font = ('Ravie', 11), textvariable = self.NameVar)
		self.nombre.pack(side = TOP, fill = X)
		self.nombre.bind("<Key>", self.Enter)
		self.texto = Entry(master, justify = CENTER, bd = 3, font = ('Ravie', 11), textvariable = self.TextVar)
		self.texto.pack(side = TOP, fill = X)
		self.texto.bind("<Key>", self.Enter)
		self.tag = Entry(master, justify = CENTER, bd = 3, font = ('Ravie', 11), textvariable = self.TagsVar)
		self.tag.pack(side = TOP, fill = X)
		self.tag.bind("<Key>", self.Enter)
		self.tree = Treeview(master)
		self.tree.pack(side = LEFT, expand = YES, fill = BOTH)
		self.tree.bind("<Double-1>", self.OnDoubleClick)

	def right_side(self, master):
		self.text = Text(master, bg = 'skyblue', bd = 5, 
					font = ('consolas', 12), fg = 'red')
		self.text.pack(expand = YES, side = LEFT, fill = BOTH)
		self.yscroller = Scrollbar(master, command = self.text.yview)
		self.yscroller.pack(side = RIGHT, fill = Y)
		self.text['yscrollcommand'] = self.yscroller

	def OnDoubleClick(self, tree):
		try:
			item = self.tree.selection()[0]
			self.tree.item.open(item)
		except IndexError:
			pass

	def Enter(self, event):
		if event.char == ord(13):
			self.buscar()

	def buscar(self):
		name = NameVar.get()
		text = TextVar().get()
		etiqueta = TagsVar.get().split(',')
		self.aciertos = []
		for carpeta in self.direc:
			root = tree.insert("", 1, name[-3], text = name[-3])
			self.aciertos = []
			for versiculo in glob("%s\*" % carpeta):
				with open(versiculo, 'r') as nota:
					texto = nota.readlines()
					etiquetas = texto[-1].split(',')
					if name != '':
						versiculo = versiculo.replace(".txt", "")
						if re.search('%s' % name, versiculo):
							pass
						else:
							continue
					if etiqueta != []:
						for i in etiquetas:
							if i in etiqueta:
								break
						else:
							continue
					if text != '':
						for line in texto:
							if re.search(r'%s' % text, line):
								break
						else:
							continue
					tree.insert(raiz, "end", name, text = name[-1])
					self.aciertos.append(versiculo)
			if self.aciertos == []:
				self.tree.delete(root)
开发者ID:ErmantrautJoel,项目名称:Python,代码行数:86,代码来源:Interfaz+Biblico.py


注:本文中的ttk.Treeview.selection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。