如何在IPython笔记本中对齐小部件按钮 [英] How to align widget buttons in IPython notebook

查看:113
本文介绍了如何在IPython笔记本中对齐小部件按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码安静

from ipywidgets import widgets
from IPython.display import display
import numpy as np

class Test(object):
    def __init__(self, arraylen):
        self.a = np.random.randn(arraylen)
        self.button = widgets.Button(description = 'Show')
        self.button.on_click(self.show)
        display(self.button)

        self.button1 = widgets.Button(description = 'Show1')
        self.button1.on_click(self.show)
        display(self.button1)

    def show(self, ev = None):
        np.savetxt('test',self.a)
        self.button.disabled = True


test = Test(10)

输出是一列中的两个按钮,如下所示:

The output is two buttons in a column as shown here:

是否也可以将按钮嵌入HTML表格(我可以选择它们在一行中),还是任何其他组织方案?也许它看起来像这样:

Would it also be possible, to embed the buttons in a HTML table (where I could choose them to be in a row), or any other organization scheme? Maybe it could look like this:

< img src =https://i.stack.imgur.com/CcLyj.pngalt =在此处输入图像说明>

推荐答案

你可以使用(一个非常基本的例子):

You could use (a very basic example):

from IPython.display import display
from ipywidgets import widgets
button1 = widgets.Button(description = 'Button1')
button2 = widgets.Button(description = 'Button2')
display(widgets.HBox((button1, button2)))

在这里,您可以找到有关使用小部件的基本和更完整的示例。如果你正在使用Jupyter,你应该调整一些信息(来自ipywidgets导入小部件的 而不是来自IPython.html import widgets ,. ..)。

Here you can find basic and more complete examples about the use of the widgets. If you are using Jupyter you should adapt some info (from ipywidgets import widgets instead from IPython.html import widgets,...).

这篇关于如何在IPython笔记本中对齐小部件按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆