Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created January 20, 2019 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigilantPotato/f47e1b7cffecf34111ef7e792287c9b7 to your computer and use it in GitHub Desktop.
Save vigilantPotato/f47e1b7cffecf34111ef7e792287c9b7 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# tkinter flashメソッドによるボタンの点滅 Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. tkinterのインポート"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import tkinter"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. ボタンクリック時に呼び出す関数\n",
" ボタンクリック時に呼び出される関数を定義。\n",
" .flash() でボタンウィジェットを点滅させる。"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def flash(event):\n",
" event.widget.flash()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. ウィジェットの生成\n",
" ボタンウィジェットを生成し、.bindでflash()を呼び出すように設定。\n",
" ボタンに色を付けておかないと点滅がわかりづらいため。bgオプションでlight blueに設定しておく。"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"root = tkinter.Tk()\n",
"b = tkinter.Button(text='flash test', bg='light blue')\n",
"b.bind('<Button-1>', flash)\n",
"b.pack()\n",
"root.mainloop()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment