mercredi 2 février 2022

how to pass the value from checkboxes in single list from Urwid?

Hi everyone I'm new with the urwid. I want to send the values of checkboxes which are selected from checkbox list it will add into the list and send this list to the next page. Here below is my code in that i am getting empty value while printing the List box value.

    from urwid import (CheckBox, SimpleListWalker, ListBox, Text, Frame,
                   MainLoop, ExitMainLoop, connect_signal)

words = ["obelus", "bumfuzzle", "rubaboo", "ballyhoo", "everywhen",
         "octothorpe", "meldrop", "sozzled", "pizazz", "pronk"]
palette = [
        ('reverse','light gray','black'),
        ('important','dark blue','light gray',('standout','underline')),
        ('buttn','white','default'),
        ('buttnf','white','dark blue','bold'),
        ('h2', 'white,underline,bold', 'dark red'),
        ('header','white','dark red', 'bold'),
        ('body', 'default', 'default'),]

def update_footer(widget, state):

  footer.set_text(", ".join([checkbox.label
                            for checkbox in checkboxes
                            if checkbox.state is True]))

checkboxes = []

for word in words:
  checkbox = CheckBox(label=word)
  connect_signal(checkbox, "postchange", update_footer)
  checkboxes.append(checkbox)

list_walker = SimpleListWalker(contents=checkboxes)

listbox = ListBox(list_walker)

footer = Text(markup="")


print(listbox)
frame = Frame(header=header , body=listbox)

MainLoop(widget=frame).run()



Aucun commentaire:

Enregistrer un commentaire