Dynamic HTML controls

alex23 wuwei23 at gmail.com
Tue Jan 12 05:30:37 CET 2010

On Jan 12, 1:26 pm, Alan Harris-Reid <aharrisr... at googlemail.com>
> Does anyone know where I can find any decent dynamically-constructed
> HTML control classes (dropdown list, table, input field, checkbox, etc.)
> written in Python.

There's pyWeb[1], which seems pretty close to what you're asking for:

  mytable = table(align='center', cellspacing=0, cellpadding=3,
  mytable.add(tr(td("first row"), td("second row")))

While it might be a little heavier than what you're after, you should
also be able to do this with ToscaWidgets[2]. You'd probably have to
make basic widgets for the general HTML controls, but that would give
you a good head-start on writing your own, more complex widgets.
Widgets can be a compilation of Python, HTML, CSS & JS. (I used this
fairly extensively when it used to be called TurboWidgets)

If you want to roll your own from scratch, I'm a big fan of the html
[3] library:

  >>> from html import HTML
  >>> h = HTML()
  >>> with h.table(border='1', width='987'):
  ...   with h.tr:
  ...     for header in ['column 1', 'column 2']:
  ...       h.th(header)
  >>> print h
  <table width="987" border="1">
  <tr><th>column 1</th><th>column 2</th></tr>

1: http://www.freenet.org.nz/python/pyweb
2: http://toscawidgets.org
3: http://pypi.python.org/pypi/html/1.7

More information about the Python-list mailing list