Skip to content Skip to sidebar Skip to footer

Pulling Content From A Selected Item In A Listbox (urwid)

I'm making a ListBox in urwid where each item is a URL pulled from a list of URLs. When an item is selected and ENTER is clicked, I'd like to pull the URL and open it in the browse

Solution 1:

In focus_widget you have the AttrMap object wrapping the text widget.

You can get the text content from a urwid.Text widget with the .text property, and you can get the widget wrapped by an urwid.AttrMap with the .base_widget attribute.

Note also that you need to check if input is equal to enter, to check for the Enter key

defhandle_input(input):
    ifinput == "enter": # Open link
        focus_widget, idx = content_container.get_focus()
        url = focus_widget.base_widget.text
        import webbrowser
        webbrowser.open(url)
    elifinputin ('q', 'Q'): # Quitraise urwid.ExitMainLoop()

Post a Comment for "Pulling Content From A Selected Item In A Listbox (urwid)"