Skip to content
Advertisement

In tkinter, how can I use a function in class A to populate a widget in class B?

Primary relevant code is in class EntryForm (around line 190) and class BookmarkAccess (around line 246)

I am sharing the global user_id as a means of querying specific rows of data from the database, after the login is completed.

My current workaround is to use a button on the final page, to populate the listbox (self.title.select) with the queries using the user_id generated post-launch.

I have attempted the following to no avail: inherit BookmarkAccess in EntryForm and pass the widget creation in a button command here. Also tried to parse a complete query on app launch with no user_id restriction and then populate listbox with only relevant user_id, which I also could not get working.

What I would like to do is on some prior screen (such as, immediately upon login and passing updated global user_id), populate the final listbox (self.title_select) so when I access that page the listbox is already full of the intended query rows.

Any assistance or guidance would be much appreicated.

Advertisement

Answer

Suggest to notify raised frame using tkinter virtual event, so that the frame can perform some action upon receiving that virtual event:

Then modify BookmarkAccess to populate the listbox upon receiving the virtual event:

Note that I have changed nested function title_filtering() to class method in order to be used in different situations. Also change to update the list box instead of destroy it and recreate new list box.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement