Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert value on TreeView Column #32

Closed
husnih opened this issue Sep 2, 2014 · 1 comment
Closed

insert value on TreeView Column #32

husnih opened this issue Sep 2, 2014 · 1 comment

Comments

@husnih
Copy link

husnih commented Sep 2, 2014

Hi Alejandro!
I need your help!
Do you explain to me what I need to insert value on TreeView Column ?
Thank You!
Regards.
Husni Ali Husni

@alejandroautalan
Copy link
Owner

Hello, husnih
Sorry for the delay, I have some work to do.

In code, you can manupulate as you like the widgets you defined and configured with pygubu-designer.

To do so, you mus get the widget instance using the builder method _get_object(widget_id)_.
Once you do that, you can call any method for that widget.

For example to add data into a treeview widget you use the _insert()_ method off the treeview instance.

A quick example:

#!/usr/bin/env python3
import tkinter as tk
import random
import pygubu


class MyApplication:
    def __init__(self, master):
        self.builder = builder = pygubu.Builder()
        builder.add_from_file("treeview.ui")

        # Create first the main window:
        mainwindow = builder.get_object('mainwindow', master)
        # Get the treeview instance
        tree = builder.get_object('treeview')

        # Populate treeview
        for i in range(0, 6):
            label = 'Level {0}'.format(i)
            column_data = (random.randint(0, 1000), random.randint(0, 100))
            itemid = tree.insert('', tk.END, text=label, values=column_data)
            for j in range(0, 4):
                label = 'Item {0}'.format(j)
                column_data = (random.randint(0, 1000), random.randint(0, 100))
                tree.insert(itemid, tk.END, text=label, values=column_data)

if __name__ == '__main__':
    root = tk.Tk()
    app = MyApplication(root)
    root.mainloop()

The ui file:

<?xml version='1.0' encoding='utf-8'?>
<interface>
  <object class="ttk.Frame" id="mainwindow">
    <property name="height">250</property>
    <property name="width">250</property>
    <layout>
      <property name="column">0</property>
      <property name="propagate">True</property>
      <property name="row">0</property>
      <property name="sticky">nesw</property>
      <rows>
        <row id="0">
          <property name="weight">1</property>
        </row>
      </rows>
      <columns>
        <column id="0">
          <property name="weight">1</property>
        </column>
      </columns>
    </layout>
    <child>
      <object class="pygubu.builder.widgets.scrollbarhelper" id="scrollbarhelper_1">
        <property name="scrolltype">both</property>
        <layout>
          <property name="column">0</property>
          <property name="propagate">True</property>
          <property name="row">0</property>
          <property name="sticky">nswe</property>
        </layout>
        <child>
          <object class="ttk.Treeview" id="treeview">
            <layout>
              <property name="column">0</property>
              <property name="propagate">True</property>
              <property name="row">0</property>
              <property name="sticky">nswe</property>
            </layout>
            <child>
              <object class="ttk.Treeview.Column" id="treecolumn">
                <property name="column_anchor">w</property>
                <property name="command">on_treecolumn_click</property>
                <property name="heading_anchor">w</property>
                <property name="stretch">True</property>
                <property name="text" translatable="yes">Tree</property>
                <property name="tree_column">True</property>
                <property name="visible">True</property>
              </object>
            </child>
            <child>
              <object class="ttk.Treeview.Column" id="column1">
                <property name="column_anchor">w</property>
                <property name="heading_anchor">center</property>
                <property name="stretch">False</property>
                <property name="text" translatable="yes">Column 1</property>
                <property name="tree_column">False</property>
                <property name="visible">True</property>
              </object>
            </child>
            <child>
              <object class="ttk.Treeview.Column" id="column2">
                <property name="column_anchor">w</property>
                <property name="heading_anchor">w</property>
                <property name="stretch">True</property>
                <property name="text" translatable="yes">Column 2</property>
                <property name="tree_column">False</property>
                <property name="visible">true</property>
                <property name="width">333</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

For more docs about tkinter widgets methods you can see this: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants