Skip to content

Instantly share code, notes, and snippets.

@Dayof
Last active August 20, 2017 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dayof/3182075a678a198565fad2f9a05d2735 to your computer and use it in GitHub Desktop.
Save Dayof/3182075a678a198565fad2f9a05d2735 to your computer and use it in GitHub Desktop.
import toga
class StartApp(toga.App):
def startup(self):
# Main window
self.main_window = toga.MainWindow(self.name)
self.main_window.app = self
# Tree data source
tree_data = {
'root1' : {},
'root2': {
'sub1_root2' : {},
'sub2_root2' : 'sub2_sub1_root2'
},
'root3': 'sub1_root3',
}
# Tree widget from Toga with data source and a function to call
# when any node is selected
self.tree = toga.Tree(['Navigate'], data=tree_data,
on_selection=self.selection_test)
# Text Input to show the text of the selected nodes
self.input = toga.TextInput(initial='No node was selected')
self.input_box = toga.Box(children=[self.input])
# Main widget of the application, show both the Tree data and the
# buttons to control thee application
frame = toga.SplitContainer()
frame.content = [self.tree, self.input_box]
# Add the main widget inside of the main application
self.main_window.content = frame
# Show the application
self.main_window.show()
def selection_test(self, nodes):
# Add the nodes texts selected by the user inside of the text input box
self.input.value = ', '.join(node.text for node in nodes)
def main():
# Start the application with the title and the name of the organization
app = StartApp('Test Tree multiple selection', 'org.pybee.test')
app.main_loop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment