Python ttk 模块,Treeview() 实例源码

我们从Python开源项目中,提取了以下38个代码示例,用于说明如何使用ttk.Treeview()

项目:qcri    作者:douville    | 项目源码 | 文件源码
def __init__(self, master, on_selected=None, **kwargs):
        tk.Frame.__init__(self, master, **kwargs)
        self._cache = {}
        self.tree = ttk.Treeview(self)
        self.tree['show'] = 'headings'
        self.tree['columns'] = ('subject', 'tests', 'status', 'bug')
        self.tree.heading('subject', text='Subject')
        self.tree.heading('tests', text='Test')
        self.tree.heading('status', text='Status')
        self.tree.heading('bug', text='Bug')
        self.tree.column('subject', width=60)
        self.tree.column('tests', width=150)
        self.tree.column('status', width=40)
        self.tree.column('bug', width=10)
        self.tree.bind('<<TreeviewSelect>>', on_selected)
        ysb = ttk.Scrollbar(self, orient='vertical', command=self.tree.yview)
        self.tree.grid(row=0, column=0, sticky='nsew')
        ysb.grid(row=0, column=1, sticky='ns')
        self.tree.configure(yscroll=ysb.set)
项目:cablefish    作者:michgur    | 项目源码 | 文件源码
def __init__(self, root):
        tk.Frame.__init__(self, root, bg='#7F7F7F')

        ttk.Style().layout('Filter.Treeview', [
            ('Treeview.entry', {
                'border': '1', 'children':
                    [('Treeview.padding', {
                        'children':
                            [('Treeview.treearea', {'sticky': 'nswe'})], 'sticky': 'nswe'
                    })],
                'sticky': 'nswe'
            })
        ])

        self.frame = tk.Frame(self)
        self.tree = ttk.Treeview(self.frame, show='tree', style='Filter.Treeview')

        # for p in root.app.protocols:
        #     print p

            # fixme
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def bk():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    bk_list = []
    bk_list.append(value)
    bk = Bookmarks(tree, io=IO())
    bk._insert_bookmarks(bk_list)

    return bk
项目:cms-dl    作者:nikhil-97    | 项目源码 | 文件源码
def show_report(self,list):
        self.report=Toplevel(root)
        self.report.title("Report")
        self.report.minsize(width=600,height=500)
        self.report_tree=ttk.Treeview(self.report,show='headings')
        self.report_tree["columns"]=("Course", "Activity")
        self.report_tree.column("Course", minwidth=350, stretch=True)
        self.report_tree.column("Activity", minwidth=50, stretch=True)
        self.report_tree.heading("Course", text="Course")
        self.report_tree.heading("Activity", text="Activity")
        for i in list:
            self.report_tree.insert('', 'end',values=(i[1], i[2]))

        self.ok=Button(self.report, text="  OK  ", font="helvetica 12", fg="black", relief=RAISED,command=self.report.destroy)
        self.report_tree.pack(fill=BOTH, expand=True, padx=(20, 20), pady=(20, 20),side=TOP)
        self.ok.pack(expand=False,padx=20,pady=10,anchor=SE,side=BOTTOM)
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def set_treeview_properties(self, element):
        """
        Set the information text for the Treeview *element*.
        """
        # set class property
        self.treeview.set(element.treeview_id, "class", element.treeview_class_name)

        # add the check marks for barcodes/variants
        if "variants" in element.labels:
            self.treeview.set(element.treeview_id, "variants", u"\u2713")
        else:
            self.treeview.set(element.treeview_id, "variants", "")
        if "barcodes" in element.labels:
            self.treeview.set(element.treeview_id, "barcodes", u"\u2713")
        else:
            self.treeview.set(element.treeview_id, "barcodes", "")

        self.treeview.set(element.treeview_id, "class", element.treeview_class_name)
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def populate_tree(self, element, parent_id=""):
        """
        Recursively populate the Treeview.

        Also populates the *id_cfgstrings*.
        """
        # insert into the Treeview
        element.treeview_id = self.treeview.insert(parent_id, "end", text=element.name, open=True)
        # add id-element pair to dictionary
        self.element_dict[element.treeview_id] = element
        # set information fields
        self.set_treeview_properties(element)

        # populate for children
        if element.children is not None:
            for child in element.children:
                self.populate_tree(child, parent_id=element.treeview_id)
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def cb_autofill_form(self, rig_target, event):
        """Auto-fill bookmark fields with details
        of currently selected Treeview entry.

        :param event: not used?
        :type event:
        :raises: none
        :returns: none
        """

        self.selected_bookmark = self.tree.focus()
        values = self.tree.item(self.selected_bookmark).get('values')
        self._clear_form(rig_target)

        cbb_mode = "cbb_mode{}".format(rig_target)
        txt_frequency = "txt_frequency{}".format(rig_target)
        txt_description = "txt_description{}".format(rig_target)

        self.params[cbb_mode].insert(0, values[1])
        self.params[txt_frequency].insert(0, values[0])
        self.params[txt_description].insert(0, values[2])
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def bk():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    bk_list = []
    bk_list.append(value)
    bk = Bookmarks(tree, io=IO())
    bk._insert_bookmarks(bk_list)

    return bk
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_len():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (len(bk.bookmarks.row_list) == 1)
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_freq():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    int(bk.bookmarks.row_list[0][0])
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_tag():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (bk.bookmarks.row_list[0][4] == "Untagged")
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_comment():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert(isinstance(bk.bookmarks.row_list[0][1], basestring))
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_import_rig_remote():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.load = MagicMock()
    bk.load.return_value = "test"
    bk._import_rig_remote("test")
    bk.load.assert_called_once_with("test", ",", silent=False)
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_import_gqrx():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_load = MagicMock()
    bk.bookmarks.csv_load.return_value = "test"
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append(["    28800000"," standing spike           "," Narrow FM           ","      10000"," Untagged"])
    bk._insert_bookmarks = MagicMock()
    bk._import_gqrx("test")
    bk._insert_bookmarks.assert_called_once_with([['28800000', 'FM', 'standing spike']])
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_len():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (len(bk.bookmarks.row_list) == 1)
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_freq():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    int(bk.bookmarks.row_list[0][0])
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_mode():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (bk.bookmarks.row_list[0][2] in CBB_MODES)
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_tag():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (bk.bookmarks.row_list[0][4] == "Untagged")
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx_comment():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert(isinstance(bk.bookmarks.row_list[0][1], basestring))
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_import_gqrx():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    value =  [u'5,955,000', u'AM', u'found on 18.34 jan 08 2015', u'O']
    tree.insert("",0,values = value)
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_load = MagicMock()
    bk.bookmarks.csv_load.return_value = "test"
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append([""])
    bk.bookmarks.row_list.append(["    28800000"," standing spike           "," Narrow FM           ","      10000"," Untagged"])
    bk._insert_bookmarks = MagicMock()
    bk._import_gqrx("test")
    bk._insert_bookmarks.assert_called_once_with([['28800000', 'FM', 'standing spike']])
项目:pydiff    作者:yebrahim    | 项目源码 | 文件源码
def create_file_treeview(self):
        self.fileTreeView = Treeview(self.main_window)
        self.fileTreeYScrollbar = Scrollbar(self.main_window, orient='vertical', command=self.fileTreeView.yview)
        self.fileTreeXScrollbar = Scrollbar(self.main_window, orient='horizontal', command=self.fileTreeView.xview)
        self.fileTreeView.configure(yscroll=self.fileTreeYScrollbar.set, xscroll=self.fileTreeXScrollbar.set)

        self.fileTreeView.grid(row=self.fileTreeRow, column=self.fileTreeCol, sticky=NS, rowspan=3)
        self.fileTreeYScrollbar.grid(row=self.fileTreeRow, column=self.fileTreeScrollbarCol, sticky=NS, rowspan=3)
        self.fileTreeXScrollbar.grid(row=self.horizontalScrollbarRow, column=self.fileTreeCol, sticky=EW)

        self.fileTreeView.tag_configure('red', background=self.redColor)
        self.fileTreeView.tag_configure('green', background=self.greenColor)
        self.fileTreeView.tag_configure('yellow', background=self.yellowColor)

        # hide it until needed
        self.fileTreeView.grid_remove()
        self.fileTreeYScrollbar.grid_remove()
        self.fileTreeXScrollbar.grid_remove()

    # Text areas
项目:autopen    作者:autopen    | 项目源码 | 文件源码
def playback(self, table):
        if(self.VEHICLE_NAME == ""):
                self.TextArea.insert(END, "Please register/log in to a vehicle.\n")
                return

        # Open database connection
        db = MySQLdb.connect("localhost","root","toor",self.VEHICLE_NAME )
        # prepare a cursor object using cursor() method
        cursor = db.cursor()

        sql = "SELECT * FROM %s ;" % table
        count = 0

        try:
            # Execute the SQL command
            cursor.execute(sql)
            # Update the Treeview
            # Fetch all the rows in a list of lists.
            results = cursor.fetchall()

            for row in results:
                cmd = "cansend %s %s#%s.%s%s.%s%s%s%s.%s" % (q.get(), row[1], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10])
                for line in execute([cmd]):
                    count = count + 1

            # Commit your changes in the database
            db.commit()
        except:
            # Rollback in case there is any error
            db.rollback()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Treeview(self.root, **kwargs)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def _setup_widgets(self):
        msg = ttk.Label(wraplength="4i", justify="left", anchor="n",
            padding=(10, 2, 10, 6),
            text=("Ttk is the new Tk themed widget set. One of the widgets it "
                  "includes is a tree widget, which can be configured to "
                  "display multiple columns of informational data without "
                  "displaying the tree itself. This is a simple way to build "
                  "a listbox that has multiple columns. Clicking on the "
                  "heading for a column will sort the data by that column. "
                  "You can also change the width of the columns by dragging "
                  "the boundary between them."))
        msg.pack(fill='x')

        container = ttk.Frame()
        container.pack(fill='both', expand=True)

        # XXX Sounds like a good support class would be one for constructing
        #     a treeview with scrollbars.
        self.tree = ttk.Treeview(columns=tree_columns, show="headings")
        vsb = ttk.Scrollbar(orient="vertical", command=self.tree.yview)
        hsb = ttk.Scrollbar(orient="horizontal", command=self.tree.xview)
        self.tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)
        self.tree.grid(column=0, row=0, sticky='nsew', in_=container)
        vsb.grid(column=1, row=0, sticky='ns', in_=container)
        hsb.grid(column=0, row=1, sticky='ew', in_=container)

        container.grid_columnconfigure(0, weight=1)
        container.grid_rowconfigure(0, weight=1)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def __place_widgets(self):
        # header frame and its widgets
        hframe = ttk.Frame(self)
        lbtn = ttk.Button(hframe, style='L.TButton', command=self._prev_month)
        rbtn = ttk.Button(hframe, style='R.TButton', command=self._next_month)
        self._header = ttk.Label(hframe, width=15, anchor='center')
        # the calendar
        self._calendar = ttk.Treeview(show='', selectmode='none', height=7)

        # pack the widgets
        hframe.pack(in_=self, side='top', pady=4, anchor='center')
        lbtn.grid(in_=hframe)
        self._header.grid(in_=hframe, column=1, row=0, padx=12)
        rbtn.grid(in_=hframe, column=2, row=0)
        self._calendar.pack(in_=self, expand=1, fill='both', side='bottom')
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Treeview(self.root, **kwargs)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def setUp(self):
        support.root_deiconify()
        self.tv = ttk.Treeview(padding=0)
项目:cablefish    作者:michgur    | 项目源码 | 文件源码
def __init__(self, root):
        tk.Frame.__init__(self, root, bg='#10253F')

        self.packet = None

        self.label_border = tk.Frame(self, bg='#7F7F7F', height=35)
        self.label_border.pack_propagate(False)
        self.label = tk.Label(self.label_border, bg='#a68c7a', fg='#10253F', anchor=tk.W, padx=10, font='TkDefaultFont 12 bold')

        self.scroll = ttk.Scrollbar(self, style='Vertical.TScrollbar', orient=tk.VERTICAL)

        ttk.Style().layout('Fields.Treeview', [('Treeview.treearea', {'sticky': 'nswe'})])
        ttk.Style().configure('Fields.Treeview', background='#10253F', foreground='#FFFFFF')

        self.frame = tk.Frame(self, bg='#10253F')
        self.tree = ttk.Treeview(self.frame, show='tree', yscroll=self.scroll.set, style='Fields.Treeview')
        self.tree.tag_configure('layer', background='#20354F')
        self.scroll.config(command=self.tree.yview)

        self.opened_layers = set()

        self.tree.bind('<Control-c>', self.copy)

        # TODO
        # self.menu = tk.Menu(self)
        # self.menu.add_command(label='Insert As Filter', command=lambda: root.searchbar.insert(self.packet.getattr()))
项目:cablefish    作者:michgur    | 项目源码 | 文件源码
def __init__(self, root):
        tk.Canvas.__init__(self, root, bg='#FEF9F4', highlightthickness=0)

        ttk.Style().layout('Packets.Treeview', [('Treeview.treearea', {'sticky': 'nswe'})])
        ttk.Style().configure('Packets.Treeview', foreground='#000000', background='#FEF9F4')

        self.packets = {}

        self.tree_frame = tk.Frame(self, bg='black')
        self.tree = ttk.Treeview(self.tree_frame, height=0, style='Packets.Treeview', show='headings')
        self.tree['columns'] = ['no', 'time', 'src', 'dst', 'protocol', 'length']
        cdata = [
            ('Index', False, 50, tk.E),
            ('Time', False, 100, tk.CENTER),
            ('Source', True, 120, tk.W),
            ('Destination', True, 120, tk.W),
            ('Protocol', True, 60, tk.CENTER),
            ('Length', False, 80, tk.E)
        ]
        self.size = 0
        for i, c in enumerate(cdata):
            cname = self.tree['columns'][i]
            self.tree.heading(cname, text=c[0])
            self.tree.column(cname, stretch=c[1], width=c[2], anchor=c[3])
        for i in range(12): self.tree.tag_configure('n%i' % i, background=colors_normal[i % 2])

        self.scroll = ttk.Scrollbar(self, style='Vertical.TScrollbar', orient=tk.VERTICAL, command=self.tree.yview)
        self.tree.configure(yscrollcommand=self.scroll.set)

        self.img = tk.PhotoImage(file='CF_back.gif').subsample(2, 2)
        self.background = self.create_image((350, 160), image=self.img, anchor=tk.CENTER)

        self.bind('<Configure>', self.recenter_bg)
        self.rb = False
项目:Jiffy    作者:h5rdly    | 项目源码 | 文件源码
def scaleup(self, event):
        '''The Treeview widget won't auto-adjust the row height, 
        so requires manual resetting upon font changing'''
        self.font['size']+=1
        self.style.configure('SearchBox.Treeview', rowheight=self.font.metrics('linespace')+1)
项目:Jiffy    作者:h5rdly    | 项目源码 | 文件源码
def scaledown(self, event):
        self.font['size']-=1
        self.style.configure('SearchBox.Treeview', rowheight=self.font.metrics('linespace')+1)
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def menu_selectall(self):
        """
        Add all elements in the Treeview to the selection.
        """
        for k in self.element_dict.keys():
            self.treeview.selection_add(k)
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def delete_element(self, tree_id):
        """
        Delete element with Treeview id *tree_id* from the tree, from the element 
        dictionary, and from the associated data structure. Recursively 
        deletes all children of *tree_id*.

        The tree should be refreshed using :py:meth:`refresh_tree` after 
        each deletion. This is the responsibility of the caller.

        """
        #if self.treeview.exists(tree_id):
        if tree_id in self.element_dict:
            # recursively delete children
            if self.element_dict[tree_id].children is not None:
                for child in self.element_dict[tree_id].children:
                    self.delete_element(child.treeview_id)

            # check if deleting the root element
            if self.root_element.treeview_id == tree_id:
                # clear the root element
                self.root_element = None
            else:
                try:
                    # remove the element from its parent's list of children
                    self.element_dict[tree_id].parent.remove_child_id(tree_id)
                except AttributeError:
                    raise AttributeError("Non-root element lacks proper parent")

            # delete the element from the dictionary
            del self.element_dict[tree_id]
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def refresh_treeview(self):
        """
        Clears the Treeview and repopulates it with the current contents of the tree.
        """
        # clear the entries in the Treeview
        for x in self.treeview.get_children():
            self.treeview.delete(x)

        # clear the id-element dictionary
        # elements may be given new id's after repopulation
        self.element_dict.clear()

        # repopulate
        if self.root_element is not None:
            self.populate_tree(self.root_element)
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def get_selected_elements(self):
        """
        Returns a list of elements that are currently selected in the Treeview.

        If no elements are selected, it returns an empty list.
        """
        return [self.get_element(x) for x in self.treeview.selection()]
项目:rig-remote    作者:Marzona    | 项目源码 | 文件源码
def test_save_gqrx():
    tree = ttk.Treeview(columns=("frequency",
                                 "mode",
                                 "description",
                                 "lockout"),
                        displaycolumns=("frequency",
                                        "mode",
                                        "description"),
                        show="headings")
    bk = Bookmarks(tree, io=IO())
    bk.bookmarks.csv_save = MagicMock()
    bk.bookmarks.return_value = None
    bk._save_gqrx("test")
    assert (isinstance(bk.bookmarks.row_list, list))
    assert (len(bk.bookmarks.row_list) == 0)
项目:code    作者:ActiveState    | 项目源码 | 文件源码
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)
项目:TabInOut    作者:nikolamilosevic86    | 项目源码 | 文件源码
def LoadFirstCfGScreen(project_name):
    top = Tix.Toplevel()
    top.protocol("WM_DELETE_WINDOW", on_closing)
    top.title("Table InfExtractor")
    top.geometry('{}x{}'.format(500, 500))
    topframe = Tix.Frame(top,height=10)
    topframe.pack()
    frame = Tix.Frame(top)
    frame.pack()
    topframe2 = Tix.Frame(top,height=10)
    topframe2.pack()
    middleframe = Tix.Frame(top)
    middleframe.pack()
    bottomframe2 = Tix.Frame(top,height=10)
    bottomframe2.pack( side = Tix.BOTTOM )
    bottomframe = Tix.Frame(top)
    bottomframe.pack( side = Tix.BOTTOM )

    name = Tix.StringVar()
    label_name = Tix.Label(frame,textvariable=name)
    name.set("Name of task:")
    label_name.pack(side = Tix.LEFT)
    name2 = Tix.StringVar()
    label_name2 = Tix.Label(frame,textvariable=name2)
    name2.set(project_name)
    label_name2.pack(side = Tix.LEFT)
    ConfigureDB = Tix.Button(frame, text="Configure Database", fg="black",command=lambda: ConfigureDatabaseScreen(project_name))
    ConfigureDB.pack( side = Tix.LEFT)
    clearTable = Tix.Button(frame, text="Clear DB Table", fg="black",command = lambda: ClearDBTables(project_name))
    clearTable.pack( side = Tix.LEFT)
    vars = FileManipulationHelper.loadVariables(project_name)
    Lb1 = ttk.Treeview(middleframe,columns=40,height=19)

    Lb1.pack()
    size = Lb1.size()
    for var in vars:
        Lb1.insert('', 'end', var, text=var)
        rules = FileManipulationHelper.loadRules(project_name,var)
        for rule in rules:
            Lb1.insert(var, 'end', text=rule)
        #Lb1.insert(size,rule)
        size = Lb1.size()
    AddVariables = Tix.Button(bottomframe, text="Add Variable", fg="black", command=lambda:AddVariable(project_name, Lb1))
    AddVariables.pack(side=Tix.LEFT)

    AddRules = Tix.Button(bottomframe, text="Add Rule", fg="black",command=lambda:AddEditRule(project_name,Lb1))
    AddRules.pack( side = Tix.LEFT)
    DeleteRule = Tix.Button(bottomframe, text="Delete Rule", fg="black",command=lambda:RemoveRule(Lb1,project_name))
    DeleteRule.pack( side = Tix.LEFT)
    EditRuleA = Tix.Button(bottomframe, text="Edit Rule", fg="black",command=lambda:EditRule(project_name,Lb1))
    EditRuleA.pack( side = Tix.LEFT)
    #MoveUpRule = Tix.Button(bottomframe, text="Move Up Rule", fg="black",command=lambda:MoveRuleUp(Lb1))
    #MoveUpRule.pack( side = Tix.LEFT)
    #MoveDownRule =Tix.Button(bottomframe, text="Move Down Rule", fg="black",command=lambda:MoveRuleDown(Lb1))
    #MoveDownRule.pack( side = Tix.LEFT)
    skip_val = 0
    Next = Tix.Button(bottomframe, text="Next", bg="green", command=lambda:MakeWorkingScreen(rules, top,project_name,skip_val))
    Next.pack( side = Tix.LEFT)