本文整理匯總了Python中ipywidgets.Widget方法的典型用法代碼示例。如果您正苦於以下問題:Python ipywidgets.Widget方法的具體用法?Python ipywidgets.Widget怎麽用?Python ipywidgets.Widget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ipywidgets
的用法示例。
在下文中一共展示了ipywidgets.Widget方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: widget_dict_to_msg
# 需要導入模塊: import ipywidgets [as 別名]
# 或者: from ipywidgets import Widget [as 別名]
def widget_dict_to_msg(msg_instance, d):
for key in d:
if isinstance(d[key], widgets.Widget):
if key == 'img':
img_msg = img_to_msg(d[key].value)
for slot in img_msg.__slots__:
setattr(msg_instance, slot, getattr(img_msg, slot))
return
else:
setattr(msg_instance, key, d[key].value)
else:
submsg = getattr(msg_instance, key)
widget_dict_to_msg(submsg, d[key])
示例2: _assign
# 需要導入模塊: import ipywidgets [as 別名]
# 或者: from ipywidgets import Widget [as 別名]
def _assign(object, value):
if isinstance(object, widgets.Widget):
object, trait = object, 'value'
else:
object, trait = object
setattr(object, trait, value)
示例3: cell
# 需要導入模塊: import ipywidgets [as 別名]
# 或者: from ipywidgets import Widget [as 別名]
def cell(row, column, value=0., type=None, color=None, background_color=None,
font_style=None, font_weight=None, style=None, label_left=None, choice=None,
read_only=False, numeric_format='0.000', date_format='YYYY/MM/DD', renderer=None, **kwargs):
"""Adds a new ``Cell`` widget to the current ``Sheet``
Args:
row (int): Zero based row index where to put the cell in the sheet
column (int): Zero based column index where to put the cell in the sheet
value (int, float, string, bool, Widget): The value of the cell
{args}
Returns:
The new ``Cell`` widget.
Example:
>>> from ipysheet import sheet, cell
>>>
>>> s1 = sheet()
>>> cell(0, 0, 36.) # The Cell type will be 'numeric'
>>> cell(1, 0, True) # The Cell type will be 'checkbox'
>>> cell(0, 1, 'Hello World!') # The Cell type will be 'text'
>>> c = cell(1, 1, True)
>>> c.value = False # Dynamically changing the cell value at row=1, column=1
"""
global _cells
if type is None:
if isinstance(value, bool):
type = 'checkbox'
elif isinstance(value, numbers.Number):
type = 'numeric'
elif isinstance(value, widgets.Widget):
type = 'widget'
else:
type = 'text'
if choice is not None:
type = 'dropdown'
style = style or {}
if color is not None:
style['color'] = color
if background_color is not None:
style['backgroundColor'] = background_color
if font_style is not None:
style['fontStyle'] = font_style
if font_weight is not None:
style['fontWeight'] = font_weight
c = Cell(value=value, row_start=row, column_start=column, row_end=row, column_end=column,
squeeze_row=True, squeeze_column=True, type=type, style=style, choice=choice,
read_only=read_only, numeric_format=numeric_format, date_format=date_format,
renderer=renderer, **kwargs)
if _hold_cells:
_cells += (c,)
else:
_last_sheet.cells = _last_sheet.cells+(c,)
if label_left:
if column-1 < 0:
raise IndexError("cannot put label to the left of column 0")
cell(row, column-1, value=label_left, font_weight='bold')
return c