git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tkinter: get ttk.combobox choices from another class


On Mon, Mar 4, 2019 at 8:46 AM Rich Shepard <rshepard at appl-ecosys.com> wrote:
> In the views module in his book the one form has a ttk.Combobox and lists
> the available values in an input_args dictionary. To allow addition of new
> choices for this column in my application they are in a separate class.

Specifically, from my reading of your example, you need a list of
strings for the applicable values.

> The middleware/controller is SQLAlchemy (postgres back end). The model.py
> contains,
> class Industries(Base):
>      __tablename__ = 'industries'
>
>      ind_name = Column(String, primary_key=True)
>
> How can I have the ttk.Combobox get the values from the Industries class?
>
> (If I confused you let me know and I'll try to clarify the situation.)

So you need to get a list of strings from SQLAlchemy. It's been a
while since I did that sort of thing, but you should be able to mess
with this independently of the ComboBox. I don't remember if you can
specifically ask for all the values for ind_name, but worst case, you
should be able to do this:

names = [ind.ind_name for ind in session.query(Industries)]

Then you can use that list in the ComboBox, once you've tested it.

ChrisA