SlideShare a Scribd company logo
1 of 15
tkinter の話
2020-09-18
西本 卓也(株式会社シュアルタ)
@nishimotz / @24motz
1
おまえ誰よ
• 京都(1996年~2002年)→ 現在は広島
• NVDA日本語チーム www.nvda.jp
• PyCon mini Hiroshima → 2020年10月10日オンライン開催
• PyCon JP 2020 でコミュニティの話をした
• すごい広島 with Pythonで「標準ライブラリなLT会」を紹介された
• ソース
• tkinterの話題
• https://gist.github.com/nishimotz/ca2d5eac2002b908a7da3aaa2f162f48
• まわり将棋
• https://gist.github.com/nishimotz/67b1e1cd245eadb2b2597db650a8c772
2
動機
• ゲームセンターあらしと学ぶ プログラミング入門
• 知り合いの息子さんと2回ほど読書会
• この本のアプローチ
• 公式 Python
• エディタは IDLE
• 標準ライブラリだけでスカッシュゲーム
• tkinter
• 扱わないこと
• クラス定義
• データ構造
3
4
Python で予約語の一覧を出す方法
• 51ページに import keyword が紹介されている
5
tkinter
• https://docs.python.org/ja/3/library/tkinter.html
• Tcl/Tk の Tk
• Tk の仕様書にたらいまわしにされる
6
tkinter/__init__.py より
7
import tkinter
from tkinter.constants import *
tk = tkinter.Tk()
frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
frame.pack(fill=BOTH,expand=1)
label = tkinter.Label(frame, text="Hello, World")
label.pack(fill=X, expand=1)
button = tkinter.Button(frame,text="Exit",command=tk.destroy)
button.pack(side=BOTTOM)
tk.mainloop()
8
9
10
多重継承による実装
• Fluent Python 第1版 第12章 継承の功罪
• 「標準ライブラリで多重継承を極端に用いている例」として紹介
11
>>> import tkinter
>>> def print_mro(cls):
... print(', '.join(c.__name__ for c in cls.__mro__))
...
>>> print_mro(tkinter.Toplevel)
Toplevel, BaseWidget, Misc, Wm, object
>>> print_mro(tkinter.Canvas)
Canvas, Widget, BaseWidget, Misc, Pack, Place, Grid, XView, YView, object
>>>
使い方(公式)
12
import tkinter as tk
class Application(tk.Frame):
(中略)
root = tk.Tk()
app = Application(master=root)
app.mainloop()
canvas が便利
13
def create_widgets(self):
self.cv = tk.Canvas(self, width=440, height=440)
# omitted
self.cv.create_text(60, 60, text="歩", tag="player")
self.cv.pack(side="top")
def set_player_pos(self, x, y):
self.cv.coords("player", x, y)
def set_player_text(self, text):
self.cv.itemconfigure("player", text=text)
def button_pressed(self):
# omitted
self.set_player_text("香")
ttk = テーマ付きウィジェット
• https://docs.python.org/ja/3/library/tkinter.ttk.html
14
>>> from tkinter import ttk
>>> import tkinter
>>> root = tkinter.Tk()
>>> ttk.Style().configure("TButton", padding=6, relief="flat", background="#ccc")
>>> btn = ttk.Button(text="Hello")
>>> btn.pack()
これから
• 「こんにちはPython」で勉強した人に...
• さらに tkinter を深掘りしてもらう?
• 割り切りが必要
• 別の GUI ツールキット?
• レトロゲームエンジン Pyxel
• https://github.com/kitao/pyxel/blob/master/README.ja.md
15

More Related Content

Similar to 200918 hannari-python

第一回テクニカルアーティストラウンドテーブル・セッション
第一回テクニカルアーティストラウンドテーブル・セッション第一回テクニカルアーティストラウンドテーブル・セッション
第一回テクニカルアーティストラウンドテーブル・セッション
fumoto kazuhiro
 

Similar to 200918 hannari-python (20)

ギークを目指すエンジニャーの 情報収集方法 mohikan Slack
ギークを目指すエンジニャーの 情報収集方法 mohikan Slackギークを目指すエンジニャーの 情報収集方法 mohikan Slack
ギークを目指すエンジニャーの 情報収集方法 mohikan Slack
 
ieLT in 2017 fall
ieLT in 2017 fall ieLT in 2017 fall
ieLT in 2017 fall
 
PyScriptの紹介
PyScriptの紹介PyScriptの紹介
PyScriptの紹介
 
181006 nishimoto-kaggle
181006 nishimoto-kaggle181006 nishimoto-kaggle
181006 nishimoto-kaggle
 
200208 osh-nishimoto-v2
200208 osh-nishimoto-v2200208 osh-nishimoto-v2
200208 osh-nishimoto-v2
 
211120 他人の書いたPythonスクリプトをステップ実行で理解する
211120 他人の書いたPythonスクリプトをステップ実行で理解する211120 他人の書いたPythonスクリプトをステップ実行で理解する
211120 他人の書いたPythonスクリプトをステップ実行で理解する
 
WebSig冬期講習2020 開校資料
WebSig冬期講習2020 開校資料WebSig冬期講習2020 開校資料
WebSig冬期講習2020 開校資料
 
Google Home をつかって おじいちゃんにGoogle Home の使い方を教える
Google Home をつかって おじいちゃんにGoogle Home の使い方を教えるGoogle Home をつかって おじいちゃんにGoogle Home の使い方を教える
Google Home をつかって おじいちゃんにGoogle Home の使い方を教える
 
イベント企画運営の経験と実際 / The history of organizing events by me
イベント企画運営の経験と実際 / The history of organizing events by meイベント企画運営の経験と実際 / The history of organizing events by me
イベント企画運営の経験と実際 / The history of organizing events by me
 
Py datameetup1
Py datameetup1Py datameetup1
Py datameetup1
 
171209 nishimoto-mpy-esp32
171209 nishimoto-mpy-esp32171209 nishimoto-mpy-esp32
171209 nishimoto-mpy-esp32
 
CoderDojo五日市 OSChiroshima2017
CoderDojo五日市 OSChiroshima2017CoderDojo五日市 OSChiroshima2017
CoderDojo五日市 OSChiroshima2017
 
東方ゲームAIとその歴史
東方ゲームAIとその歴史東方ゲームAIとその歴史
東方ゲームAIとその歴史
 
Rubyだけでチンチロをつくる
RubyだけでチンチロをつくるRubyだけでチンチロをつくる
Rubyだけでチンチロをつくる
 
Pythonで ハードウェアを動かす楽しさと ハードウェアハック始めたきっかけ
Pythonで ハードウェアを動かす楽しさと ハードウェアハック始めたきっかけPythonで ハードウェアを動かす楽しさと ハードウェアハック始めたきっかけ
Pythonで ハードウェアを動かす楽しさと ハードウェアハック始めたきっかけ
 
第一回テクニカルアーティストラウンドテーブル・セッション
第一回テクニカルアーティストラウンドテーブル・セッション第一回テクニカルアーティストラウンドテーブル・セッション
第一回テクニカルアーティストラウンドテーブル・セッション
 
Pythonの10年と今、これから
Pythonの10年と今、これからPythonの10年と今、これから
Pythonの10年と今、これから
 
Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )
 
Git for Begineers GitHub ハンズオン
Git for Begineers GitHub ハンズオンGit for Begineers GitHub ハンズオン
Git for Begineers GitHub ハンズオン
 
YAPCレポートの舞台裏
YAPCレポートの舞台裏YAPCレポートの舞台裏
YAPCレポートの舞台裏
 

More from Takuya Nishimoto

More from Takuya Nishimoto (20)

221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ている221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ている
 
220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集
 
220126 python-datalake-spark
220126 python-datalake-spark220126 python-datalake-spark
220126 python-datalake-spark
 
211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10
 
210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれから210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれから
 
210911 これから始める電子工作とMicroPython
210911 これから始める電子工作とMicroPython210911 これから始める電子工作とMicroPython
210911 これから始める電子工作とMicroPython
 
210728 mpy
210728 mpy210728 mpy
210728 mpy
 
210630 python
210630 python210630 python
210630 python
 
210526 Power Automate Desktop Python
210526 Power Automate Desktop Python210526 Power Automate Desktop Python
210526 Power Automate Desktop Python
 
210428 python
210428 python210428 python
210428 python
 
200429 python
200429 python200429 python
200429 python
 
200325 flask
200325 flask200325 flask
200325 flask
 
191208 python-kansai-nishimoto
191208 python-kansai-nishimoto191208 python-kansai-nishimoto
191208 python-kansai-nishimoto
 
191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimoto191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimoto
 
191114 iotlt-nishimoto
191114 iotlt-nishimoto191114 iotlt-nishimoto
191114 iotlt-nishimoto
 
191030 anna-with-python
191030 anna-with-python191030 anna-with-python
191030 anna-with-python
 
190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjp190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjp
 
190925 python-windows
190925 python-windows190925 python-windows
190925 python-windows
 
190731 chalice
190731 chalice190731 chalice
190731 chalice
 
190719 nishimoto nvda talk
190719 nishimoto nvda talk190719 nishimoto nvda talk
190719 nishimoto nvda talk
 

Recently uploaded

Recently uploaded (12)

Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 

200918 hannari-python