in reply to Editable tree in Tk

If you are willing to move up to Perl/Gtk2, it has a nice editable treeview.
#! /usr/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; #standard window creation, placement, and signal connecting my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_border_width(5); $window->set_position('center_always'); #this vbox will geturn the bulk of the gui my $vbox = &ret_vbox(); #add and show the vbox $window->add($vbox); $window->show(); #our main event-loop Gtk2->main(); ###################################################################### +## sub ret_vbox { my $vbox = Gtk2::VBox->new(FALSE,5); $vbox->set_size_request (300, 300); #this is one of the provided base Gtk2::TreeModel classes. my $tree_store = Gtk2::TreeStore->new(qw/Glib::String/); #fill it with arbitry data foreach (1..3) { my $parent_nr = $_; my $iter = $tree_store->append(undef); $tree_store->set ($iter,0 => "Parent $parent_nr"); foreach (1..3){ my $iter_child = $tree_store->append($iter); $tree_store->set ($iter_child,0 => "Child $_ of Parent $pa +rent_nr"); } } #this will create a treeview, specify $tree_store as its model my $tree_view = Gtk2::TreeView->new($tree_store); #create a Gtk2::TreeViewColumn to add to $tree_view my $tree_column = Gtk2::TreeViewColumn->new(); $tree_column->set_title ("Click to sort"); my $renderer = Gtk2::CellRendererText->new; $renderer->set_property('editable' => TRUE); $renderer->signal_connect (edited => \&cell_edited, $tree_ +store); $tree_column->pack_start ($renderer, FALSE); $tree_column->add_attribute($renderer, text => 0); #add $tree_column to the treeview $tree_view->append_column ($tree_column); $vbox->pack_start($tree_view,TRUE,TRUE,0); $vbox->show_all(); return $vbox; } sub cell_edited { my ($cell, $path_string, $new_text, $model) = @_; my $path = Gtk2::TreePath->new_from_string ($path_string); my $column = $cell->get_data ("column"); my $iter = $model->get_iter ($path); $model->set_value ($iter, $column, $new_text); }

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: Editable tree in Tk
by anna_black (Sexton) on Dec 25, 2008 at 13:16 UTC

    Unfotunately, I'm limited by what's installed at work... So Gtk2 is not an option.

    I actually found that embedding tree-like buttons into a Text widget is good enough for my purposes. Now I just have to figure out what I'm doing wrong when I'm trying to replace the button by a different one... :)

      Show a simple example and we might figure out the problem.

      I'm not really a human, but I play one on earth Remember How Lucky You Are

        After some digging, I figured it out. I was deleting a button from the Text widget, as you'd delete text, but that destroys the button completely, so I got an error the next time I tried to re-insert it. It was still in my hash of buttons, though, which made me thing the button still exists. Took me a while to debug my sample code until I made it do what I want :)

        If anyone's interested, I'm attaching my sample code. Now on to changing the original to behave the same way...

        EDIT: I just checked out the code in your other reply, and though I think that for now I'll stay with my version, I definitely learned a couple of new things from it. Thanks!