LoginSignup
2
4

More than 5 years have passed since last update.

python3でボタンのクリックイベントを使う

Last updated at Posted at 2018-07-31

python3でボタンを使ってみる。

#モジュールのインポート
from ipywidgets import widgets
from IPython.display import display

#文字列の定義
x = "ボタン1"
y = "ボタン2"
click = "をクリックしました。"

#ボタンを作成("description"に、ボタンに表示する文字列を代入。)
button1 = widgets.Button(description = x)
button2 = widgets.Button(description = y)

#クリックイベントを定義
def click1():
    print(x + click)
def click2():
    print(y + click)

#ボタンにクリックイベントを実装
button1.on_click(click1)
button2.on_click(click2)

#ボタンを表示
display(button1)
display(button2)
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4