alejandroautalan / pygubu

A simple GUI builder for the python tkinter module
MIT License
2.02k stars 212 forks source link

Click button then values of Combobox change. #211

Closed santi2fx closed 4 years ago

santi2fx commented 4 years ago

Please help me. I have data are 'A B C D E' and I would like to change data are '1 2 3 4 5' by click button. please see picture

Thank you for your support. myapp_pygubu1 myapp_pygubu2 myapp_pygubu3

alejandroautalan commented 4 years ago

Hello santi2fx, thanks for trying pygubu. Here is a minimal example:

File: issue211app.py

import os
import pygubu

PROJECT_PATH = os.path.dirname(__file__)
PROJECT_UI = os.path.join(PROJECT_PATH, "issue211.ui")

class Issue211App:
    def __init__(self):
        self.builder = builder = pygubu.Builder()
        builder.add_resource_path(PROJECT_PATH)
        builder.add_from_file(PROJECT_UI)
        self.mainwindow = builder.get_object('toplevel1')
        builder.connect_callbacks(self)

        self.combo1 = builder.get_object('combo1')

    def on_change_data(self):
        new_data = '1 2 3 4 5'
        self.combo1.set('')
        self.combo1.config(values=new_data)

    def run(self):
        self.mainwindow.mainloop()

if __name__ == '__main__':
    app = Issue211App()
    app.run()

File: issue211.ui

<?xml version='1.0' encoding='utf-8'?>
<interface version="1.0">
  <object class="tk.Toplevel" id="toplevel1">
    <property name="geometry">320x200</property>
    <property name="height">200</property>
    <property name="width">200</property>
    <child>
      <object class="ttk.Frame" id="fcontainer">
        <property name="height">200</property>
        <property name="width">200</property>
        <layout manager="pack">
          <property name="propagate">True</property>
          <property name="side">top</property>
        </layout>
        <child>
          <object class="ttk.Labelframe" id="labelframe_1">
            <property name="height">200</property>
            <property name="text" translatable="yes">Umbrella</property>
            <property name="width">200</property>
            <layout manager="pack">
              <property name="propagate">True</property>
              <property name="side">top</property>
            </layout>
            <child>
              <object class="ttk.Combobox" id="combo1">
                <property name="values">A B C D E F</property>
                <layout manager="pack">
                  <property name="propagate">True</property>
                  <property name="side">top</property>
                </layout>
              </object>
            </child>
            <child>
              <object class="ttk.Button" id="button1">
                <property name="command">on_change_data</property>
                <property name="text" translatable="yes">Change data</property>
                <layout manager="pack">
                  <property name="propagate">True</property>
                  <property name="side">top</property>
                </layout>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

Regards, Alejandro A.

santi2fx commented 4 years ago

Thank you very much.