Git Product home page Git Product logo

Comments (1)

alejandroautalan avatar alejandroautalan commented on May 20, 2024

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

from pygubu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.