tkinter - RIP Tutorialimport ttk Python 3.xでのインポート はPython...

35
tkinter #tkinter

Transcript of tkinter - RIP Tutorialimport ttk Python 3.xでのインポート はPython...

  • tkinter

    #tkinter

  • 1

    1: tkinter 2

    2

    Python 2Python 3 2

    Python 2.x 2

    Python 3.x 2

    2

    3

    Tcl 3

    Python 3

    Examples 4

    4

    5

    6

    2: Tkinter 8

    8

    8

    8

    Examples 8

    8

    Entry 8

    9

    int 9

    3: Tkinter 10

    10

    Examples 10

    10

    11

    12

    4: Tkinter 15

    15

  • 15

    15

    Examples 16

    16

    16

    5: Ttk 17

    17

    17

    17

    17

    Examples 17

    17

    17

    17

    18

    18

    18

    19

    19

    19

    19

    19

    0.5 19

    6: ttk 21

    21

    Examples 21

    21

    7: 23

    23

    23

  • 23

    23

    Examples 23

    23

    24

    24

    8: / 25

    25

    Examples 25

    Tkinter 25

    .GIF 25

    9: TopLevel 26

    Examples 26

    TkToplevel 26

    .lift 27

    10: 29

    29

    29

    29

    Examples 29

    .after 29

    31

  • You can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: tkinter

    It is an unofficial and free tkinter ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official tkinter.

    The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.

    Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to [email protected]

    https://riptutorial.com/ja/home 1

    http://riptutorial.com/ebook/tkinterhttps://archive.org/details/documentation-dump.7zmailto:[email protected]

  • 1: tkinterのいTkinter「 Tk Inter face」は、グラフィカルユーザーインターフェイスGUIをするためのPythonのクロスプラットフォームパッケージです。これはTkツールキットをってとなるTclインタプリタへのアクセスをします。それはクロスプラットフォームのグラフィカルユーザインタフェースライブラリです。

    TkinterはPythonののGUIライブラリではありませんが、でされています。 PythonでできるそののGUIライブラリには、 wxPython 、 PyQt 、およびkivyがあります。

    Tkinterののみは、とシンプルさです。これは、ほとんどのプラットフォームLinux、OSX、Windowsののでし、もなタスクボタン、ラベル、キャンバス、テキストなどにないウィジェットをえています。

    ツールとして、tkinterには、きフォント、バインドタグ、トレースなどのGUIツールキットにのがいくつかあります。

    Python 2とPython 3のいTkinterはPython 2とPython 3のではほとんどわりません。ないは、tkinterパッケージとモジュールのがされたことです。

    Python 2.xでのインポート

    Python 2.xでは、tkinterパッケージのはTkinterであり、するパッケージはのをっています。たとえば、のは、Python 2.xのなimportのセットをしています。

    import Tkinter as tk import tkFileDialog as filedialog import ttk

    Python 3.xでのインポート

    はPython 2と3のであまりしませんでしたが、すべてのtkinterモジュールのがされました。は、Python 3.xのなimportのセットです

    import tkinter as tk from tkinter import filedialog from tkinter import ttk

    StackoverflowのTkinterの••

    https://riptutorial.com/ja/home 2

    https://wxpython.org/what.phphttps://riverbankcomputing.com/software/pyqt/introhttps://kivy.org/#homehttps://kivy.org/#homehttp://stackoverflow.com/questions/tagged/tkinterhttp://stackoverflow.com/questions/tagged/tkinterhttp://stackoverflow.com/questions/tagged/tkinterhttp://stackoverflow.com/questions/tagged/tkinterhttp://stackoverflow.com/questions/tagged/tkinterhttp://stackoverflow.com/questions/tagged/tkinterhttps://docs.python.org/3.5/library/tkinter.htmlhttps://docs.python.org/3.5/library/tkinter.html

  • のPython 3 tkinterのドキュメントのPython 2 tkinterのドキュメント•Tkdocs.com - マルチプラットフォームtkドキュメント•tkinterへのEffbotの•Tkinterリファレンスガイド、New Mexico Tech•

    バージョン

    Tcl

    バージョン

    8.6 2016-07-27

    8.5 2016-02-12

    8.4 2013-06-01

    8.3 20021018

    8.2 1999-12-16

    8.1 1999-05-26

    8.0 1999-03-09

    Python

    バージョン

    3.6 2016-12-23

    3.5 2015-09-13

    3.4 2014-03-17

    3.3 2012-09-29

    3.2 20110220

    3.1 2009-06-26

    3.0 2008-12-03

    2.7 2010-07-03

    2.6 2008102

    https://riptutorial.com/ja/home 3

    https://docs.python.org/3.5/library/tkinter.htmlhttps://docs.python.org/3.5/library/tkinter.htmlhttps://docs.python.org/3.5/library/tkinter.htmlhttps://docs.python.org/3.5/library/tkinter.htmlhttps://docs.python.org/2.7/library/tkinter.htmlhttps://docs.python.org/2.7/library/tkinter.htmlhttps://docs.python.org/2.7/library/tkinter.htmlhttps://docs.python.org/2.7/library/tkinter.htmlhttps://docs.python.org/2.7/library/tkinter.htmlhttps://docs.python.org/2.7/library/tkinter.htmlhttp://tkdocs.comhttp://tkdocs.comhttp://tkdocs.comhttp://tkdocs.comhttp://effbot.org/tkinterbook/tkinter-index.htm#introductionhttp://effbot.org/tkinterbook/tkinter-index.htm#introductionhttp://effbot.org/tkinterbook/tkinter-index.htm#introductionhttp://effbot.org/tkinterbook/tkinter-index.htm#introductionhttp://effbot.org/tkinterbook/tkinter-index.htm#introductionhttp://effbot.org/tkinterbook/tkinter-index.htm#introductionhttp://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.htmlhttp://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.htmlhttp://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.htmlhttp://www.tcl.tk/software/tcltk/8.6.htmlhttp://www.tcl.tk/software/tcltk/8.5.htmlhttp://www.tcl.tk/software/tcltk/8.4.htmlhttp://www.tcl.tk/software/tcltk/8.3.htmlhttp://www.tcl.tk/software/tcltk/8.2.htmlhttp://www.tcl.tk/software/tcltk/8.1.htmlhttp://www.tcl.tk/software/tcltk/8.0.htmlhttps://www.python.org/downloads/release/python-360/https://www.python.org/downloads/release/python-350/https://www.python.org/download/releases/3.4.0/https://www.python.org/download/releases/3.3.0/https://www.python.org/download/releases/3.2/https://www.python.org/download/releases/3.1/https://www.python.org/download/releases/3.0/https://www.python.org/download/releases/2.7/https://www.python.org/download/releases/2.6/

  • バージョン

    2.5 2006-09-19

    2.4 2004-11-30

    2.3 2003729

    2.2 20011221

    2.1 2001-04-15

    2.0 2000-10-16

    Examples

    インストールまたはセットアップ

    Tkinterには、Mac OS XとWindowsプラットフォームのPythonインストーラバイナリがあらかじめインストールされています。したがって、Mac OS XまたはWindowsプラットフォームのバイナリからPythonをインストールするは、Tkinterをうのがよいでしょう。

    DebianバージョンのLinuxでは、のコマンドをってでインストールするがあります。

    Python 3の

    sudo apt-get python3-tkをインストールする

    Python 2.7の

    sudo apt-get python-tkをインストールする

    yumインストーラをしているLinuxディストリビューションでは、のコマンドをしてtkinterモジュールをインストールできます。

    yum install tkinter

    インストールの

    Tkinterがにインストールされたかどうかをするには、Pythonコンソールをいてのコマンドをします。

    import tkinter as tk # for Python 3 version

    または

    import Tkinter as tk # for Python 2.x version

    https://riptutorial.com/ja/home 4

    https://www.python.org/download/releases/2.5/https://www.python.org/download/releases/2.4/https://www.python.org/download/releases/2.3/https://www.python.org/download/releases/2.2/https://www.python.org/download/releases/2.1/https://www.python.org/download/releases/2.0/https://www.python.org/downloads/https://www.python.org/downloads/https://www.python.org/downloads/https://www.python.org/downloads/

  • のコマンドがエラーなしでされたは、Tkinterがにインストールされています。

    Tkinterのバージョンをするには、Python REPLにのコマンドをします

    Python 3.X

    import tkinter as tk tk._test()

    Python 2.X

    import Tkinter as tk tk._test()

    Tkinter as tkインポートはではありませんが、バージョンのをつのにちます。

    こんにちは

    な "Hello、World"をして、tkinterのをテストしましょう。プログラム。

    まず、tkinterをインポートするがあります。これはバージョンによってなります「Python 2と3のい」を

    Python 3では、モジュールtkinterはのtをちます

    import tkinter as tk

    Python 2では、モジュールTkinterにはのT

    import Tkinter as tk

    as tkはにはではありませんが、こののりのはのバージョンでじようにします。

    tkinterモジュールをインポートしたので、 Tkクラスをしてアプリケーションのルートをできます。

    root = tk.Tk()

    これはアプリケーションのウィンドウとしてします。 のウィンドウは、わりにToplevelインスタンスでなければならないことにしてください

    これでウィンドウができたので、 Labelをけてテキストをしましょう

    label = tk.Label(root, text="Hello World!") # Create a text label label.pack(padx=20, pady=20) # Pack it into the window

    アプリケーションのができたら、 mainloopメソッドをってアプリケーションをする メインイベン

    https://riptutorial.com/ja/home 5

  • トループにる

    root.mainloop()

    これは、ウィンドウがじられたときにアプリケーションがするか、 root.destroy()などのコールバックからをびすまで、アプリケーションをいてします。

    すべてをにれて

    import tkinter as tk # Python 3.x Version #import Tkinter as tk # Python 2.x Version root = tk.Tk() label = tk.Label(root, text="Hello World!") # Create a text label label.pack(padx=20, pady=20) # Pack it into the window root.mainloop()

    そして、このようなものがポップアップするはずです

    こんにちは モジュラ、オブジェクト

    import tkinter as tk class HelloWorld(tk.Frame): def __init__(self, parent): super(HelloWorld, self).__init__(parent) self.label = tk.Label(self, text="Hello, World!") self.label.pack(padx=20, pady=20) if __name__ == "__main__": root = tk.Tk() main = HelloWorld(root) main.pack(fill="both", expand=True) root.mainloop()

    ルートウィンドウをむtkinterウィジェットからすることはです。 tkinter.Frameからすることは、

    https://riptutorial.com/ja/home 6

    https://i.stack.imgur.com/DreFs.png

  • のドキュメントインターフェイスMDI、ドキュメントインターフェイスSDI、シングルページアプリケーション、およびページアプリケーションをサポートするというでなくとももがあります。

    オンラインでtkinterのいをむ https://riptutorial.com/ja/tkinter/topic/987/tkinterのい

    https://riptutorial.com/ja/home 7

    https://riptutorial.com/ja/tkinter/topic/987/tkinter%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9https://riptutorial.com/ja/tkinter/topic/987/tkinter%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9https://riptutorial.com/ja/tkinter/topic/987/tkinter%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9https://riptutorial.com/ja/tkinter/topic/987/tkinter%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9https://riptutorial.com/ja/tkinter/topic/987/tkinter%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9

  • 2: Tkinterエントリーウィジェットエントリ= tk.Entry 、** kwargs •entry.get•entry.insertindex、 "value"•entry.deletestart_index、end_index•entry.bindイベント、コールバック•

    パラメーター

    パラメータ

    tkinterウィジェットはヒエラキーにします。ルートウィンドウをいて、すべてのウィジェットにはがあります。のオンラインチュートリアルでは、この「マスター」とばれています。ウィジェットがpack 、 placeまたはgridでにされると、このウィジェットがこのウィジェットのにされます

    widthは、にづいてウィジェットののをします 。フォントの、これはゼロの 0 にづいています。デフォルトは20です。のは、にどのようにされるかによってきくなるもあればさくなるもあります。

    これらのでは、tkinter import tkinter as tk tminter import tkinter as tk 3またはimport Tkinter as tk import Tkinter as tk python 2をimport tkinter as tkてインポートしたとしています。

    Examples

    エントリウィジェットのとデフォルトの

    entry = tk.Entry(parent, width=10) entry.insert(0, "Hello, World!")

    Entryウィジェットのをる

    エントリウィジェットのは、ウィジェットのgetメソッドでgetます。

    name_entry = tk.Entry(parent) ... name = name_entry.get()

    にじて、 StringVarインスタンスをけて、ウィジェットからではなくStringVarからをすることもで

    https://riptutorial.com/ja/home 8

  • きます。

    name_var = tk.StringVar() name_entry = tk.Entry(parent, textvariable=name_var) ... name = name_var.get()

    エントリウィジェットへのの

    なをウィジェットにするには、えばのみをすると、validateコマンドをそのエントリにすることができます。 validateコマンドは、がけれられるとTrueをし、それのはFalseをすです。このは、エントリのがされるたびにびされます。の、、されたテキストなど、さまざまなをこのにすことができます。

    def only_numbers(char): return char.isdigit() validation = parent.register(only_numbers) entry = Entry(parent, validate="key", validatecommand=(validation, '%S'))

    validateオプションは、バリデーションをトリガするイベントのタイプをします。ここでは、エントリののキーストロークです。 validatecommandオプションの'%S'は、またはされたがでonly_numbersにされることをonly_numbersます。のなリストはここでつけることができます 。

    エントリーウィジェットからintをする

    .getメソッドをする、エントリウィジェットにあるものはすべてにされます。たとえば、のタイプまたはになく、のはになります。ユーザーが4をすると、のようには「4」になります。 Entryウィジェットからintをするには、まず.getメソッドをびします。

    What_User_Wrote = Entry.get()

    はそのをのようにintにします

    Convert_To_Int = int(What_User_Wrote)

    に、をしたいは、のをうだけです。

    Convert_To_Int = int(Entry.get())

    strをintにしたくないは、のをできます。

    オンラインでTkinterエントリーウィジェットをむ https://riptutorial.com/ja/tkinter/topic/4868/tkinterエントリーウィジェット

    https://riptutorial.com/ja/home 9

    http://%20http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/entry-validation.htmlhttp://%20http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/entry-validation.htmlhttps://riptutorial.com/ja/tkinter/topic/4868/tkinter%E3%82%A8%E3%83%B3%E3%83%88%E3%83%AA%E3%83%BC%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88https://riptutorial.com/ja/tkinter/topic/4868/tkinter%E3%82%A8%E3%83%B3%E3%83%88%E3%83%AA%E3%83%BC%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88

  • 3: Tkinterジオメトリマネージャー

    ウィジェットのには、 pack() 、 grid() 、 place() 3つのジオメトリ・マネージャがあります。

    Examples

    パック

    pack()ジオメトリマネージャは、ウィジェットをウィジェットにするにブロックでウィジェットをします。それは、 fill 、 expand 、およびsideオプションをします。

    widget.pack(option)

    りつぶす ウィジェットがのスペースをするか、それにりてられたなスペースをするかどうかをします。NONEデフォルト、Xにりつぶす、Yにりつぶす、BOTHとのをりつぶす。

    する YESにすると、ウィジェットのでされていないスペースをめるようにウィジェットがされます。YES、NO。

    ウィジェットののどちらにパックするかをします。TOPデフォルト、BOTTOM、LEFT、またはRIGHT。

    from tkinter import * root = Tk() btn_fill = Button(root, text="Button") btn_fill.pack(fill=X) btn_expand = Button(root, text="Button") btn_expand.pack(expand=YES) btn_side = Button(root, text="Button") btn_side.pack(side=RIGHT) root.mainloop()

    https://riptutorial.com/ja/home 10

  • グリッド

    grid()ジオメトリ・マネージャは、ウィジェットののようなのウィジェットをします。マスターウィジェットはとにされ、テーブルのはウィジェットをできます。これは、 column 、 columnspan 、 ipadx 、 ipady 、 padx 、 pady 、 row 、 rowspan 、 stickyます。

    widget.grid(options)

    カラム ウィジェットをする。デフォルトのは0で、のです。

    スパン いくつのウィジェットがされますか。デフォルトは1です。

    Ipadx ウィジェットのでにウィジェットをめむピクセル。

    アイパディ ウィジェットのでにウィジェットをめむピクセル。

    Padx ウィジェットののににウィジェットをめむピクセル。

    パディ ウィジェットののでウィジェットをにいくつのピクセルにするか。

    ウィジェットをする。デフォルトのは0で、のです。

    ウィジェットがめるの。デフォルトは1です。

    ウィジェットがセルよりもさい、ウィジェットがstickyセルのとをすためにstickyがされます。は、N、E、S、W、NE、NW、SE、SWのコンパスのとゼロによってされます。これらはでもかまいません。えば、NESWはウィジェットがセルのをめるようにします。

    from tkinter import * root = Tk() btn_column = Button(root, text="I'm in column 3")

    https://riptutorial.com/ja/home 11

    https://i.stack.imgur.com/AOcN1.jpg

  • btn_column.grid(column=3) btn_columnspan = Button(root, text="I have a columnspan of 3") btn_columnspan.grid(columnspan=3) btn_ipadx = Button(root, text="ipadx of 4") btn_ipadx.grid(ipadx=4) btn_ipady = Button(root, text="ipady of 4") btn_ipady.grid(ipady=4) btn_padx = Button(root, text="padx of 4") btn_padx.grid(padx=4) btn_pady = Button(root, text="pady of 4") btn_pady.grid(pady=4) btn_row = Button(root, text="I'm in row 2") btn_row.grid(row=2) btn_rowspan = Button(root, text="Rowspan of 2") btn_rowspan.grid(rowspan=2) btn_sticky = Button(root, text="I'm stuck to north-east") btn_sticky.grid(sticky=NE) root.mainloop()

    place()マネージャは、ウィジェットをウィジェットののにすることによってウィジェットをします。このジオメトリマネージャは、オプションのanchor 、 bordermode 、 height 、 width 、 relheight 、 relwidth 、 relx 、 rely 、 xとy 。

    アンカー ウィジェットがされているをします。 N、E、S、W、NE、NW、SE、SWの4つのオプションがあります。これらはウィジェットのとにしています。デフォルトはNWウィジェットのです。

    ボーダーモード Bordermodeには2つのオプションがあるINSIDEのオプションは、のをしていることをし、のをし、 OUTSIDE 、です。

    https://riptutorial.com/ja/home 12

    https://i.stack.imgur.com/XTc9h.jpg

  • さ ウィジェットのさをピクセルでします。

    ウィジェットのをピクセルでします。

    リハビリ さはウィジェットのさのとして0.01.0ののです。

    ウィジェットののとして、0.01.0ののfloatとしての。

    Relx ウィジェットののとして、0.01.0ののとしてのオフセット。

    む ウィジェットのさのとして、0.01.0ののとしてのオフセット。

    バツ ピクセルのオフセット。

    Y ピクセルのオフセット。

    from tkinter import * root = Tk() root.geometry("500x500") btn_height = Button(root, text="50px high") btn_height.place(height=50, x=200, y=200) btn_width = Button(root, text="60px wide") btn_width.place(width=60, x=300, y=300) btn_relheight = Button(root, text="Relheight of 0.6") btn_relheight.place(relheight=0.6) btn_relwidth= Button(root, text="Relwidth of 0.2") btn_relwidth.place(relwidth=0.2) btn_relx=Button(root, text="Relx of 0.3") btn_relx.place(relx=0.3) btn_rely=Button(root, text="Rely of 0.7") btn_rely.place(rely=0.7) btn_x=Button(root, text="X = 400px") btn_x.place(x=400) btn_y=Button(root, text="Y = 321") btn_y.place(y=321) root.mainloop()

    https://riptutorial.com/ja/home 13

  • オンラインでTkinterジオメトリマネージャーをむ https://riptutorial.com/ja/tkinter/topic/9620/tkinterジオメトリマネージャー

    https://riptutorial.com/ja/home 14

    https://i.stack.imgur.com/HBBkv.jpghttps://riptutorial.com/ja/tkinter/topic/9620/tkinter%E3%82%B8%E3%82%AA%E3%83%A1%E3%83%88%E3%83%AA%E3%83%9E%E3%83%8D%E3%83%BC%E3%82%B8%E3%83%A3%E3%83%BChttps://riptutorial.com/ja/tkinter/topic/9620/tkinter%E3%82%B8%E3%82%AA%E3%83%A1%E3%83%88%E3%83%AA%E3%83%9E%E3%83%8D%E3%83%BC%E3%82%B8%E3%83%A3%E3%83%BC

  • 4: Tkinterラジオボタンウィジェットラジオボタン= tkラジオボタン、** kwargs•

    パラメーター

    パラメータ

    tkinterウィジェットはにします。ルートウィンドウをいて、すべてのウィジェットにはがあります。のオンラインチュートリアルでは、この「マスター」とばれています。ウィジェットがpack、placeまたはgridでにされると、そのウィジェットはこのウィジェットのにされます。

    コマンド

    ユーザーがラジオボタンのをするたびにびされる

    1またはラジオボタンのはTrue、ボタンボックスのは0またはFalse

    テキスト

    ラジオボタンのにするテキスト。

    ラジオボタンがされると、するがにされます。

    グループののラジオボタンとラジオボタンのをする。

    これらのでは、tkinter import tkinter as tk tminter import tkinter as tk 3またはimport Tkinter as tk import Tkinter as tk python 2をimport tkinter as tkてインポートしたとしています。

    のをラジオボタンのセットではなく「ボタンボックス」にするには、indicatoronオプションを0にします。この、ラジオボタンのインジケータはで、されたボタンはRAISEDではなくSUNKENとしてされます。

    https://riptutorial.com/ja/home 15

    https://i.stack.imgur.com/mR7SL.png

  • - エフェボット

    Examples

    ラジオボタンをボタンボックスにするのをにします。

    import tkinter as tk root = tk.Tk() rbvar = StringVar() rbvar.set(" ") rb1 = tk.Radiobutton(root, text="Option 1", variable=rbvar, value='a', indicatoron=0) rb1.pack() rb2 = tk.Radiobutton(root, text="Option 2", variable=rbvar, value='b', indicatoron=0) rb2.pack()

    ラジオボタンのグループをする

    このようなグループは、1つしかできないようにをするラジオボタンでされています。

    # control variable var = tk.IntVar(parent, 0) # group of radiobuttons for i in range(1,4): tk.Radiobutton(parent, text='Choice %i' % i, value=i, variable=var).pack() tk.Button(parent, text='Print choice', command=lambda: print(var.get())).pack()

    オンラインでTkinterラジオボタンウィジェットをむ https://riptutorial.com/ja/tkinter/topic/6338/tkinterラジオボタンウィジェット

    https://riptutorial.com/ja/home 16

    https://i.stack.imgur.com/6Nwdz.pnghttp://effbot.org/tkinterbook/radiobutton.htmhttps://riptutorial.com/ja/tkinter/topic/6338/tkinter%E3%83%A9%E3%82%B8%E3%82%AA%E3%83%9C%E3%82%BF%E3%83%B3%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88https://riptutorial.com/ja/tkinter/topic/6338/tkinter%E3%83%A9%E3%82%B8%E3%82%AA%E3%83%9C%E3%82%BF%E3%83%B3%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88

  • 5: Ttkウィジェット

    なるttkウィジェットのTtkには17のウィジェットがあり、そのうちの11はすでにtkintertkにしていました。

    ttkモジュールをすると、アプリケーションのモダンでされたがられます。

    ツリー= ttk.Treeviewマスター、** kwargs•

    パラメーター

    パラメータ

    マスター

    tkinterウィジェットはヒエラキーにします。ルートウィンドウをいて、すべてのウィジェットには「マスター」ともばれますがあります。ウィジェットがpack、placeまたはgridでにされると、このウィジェットがこのウィジェットのにされます

    これらのでは、tkinter import tkinter as tk tminter import tkinter as tk 3またはimport Tkinter as tk import Tkinter as tk python 2をimport tkinter as tkてインポートしたとしています。

    また、ttkがtkinter from tkinter import ttk python 3かimport ttk python 2のどちらかfrom tkinter import ttkされているとします。

    Examples

    ツリービューな

    このウィジェットは、をつアイテムをするためにされます。たとえば、Windowsエクスプローラはこのようにできます。 treeviewウィジェットをってなテーブルをることもできます。

    ウィジェットをするtree=ttk.Treeview(master)

    https://riptutorial.com/ja/home 17

  • ユーザーがストレッチをうときに、の、、をできます。 stretch=tk.NOすることで、ユーザーはのをできません。

    tree["columns"]=("one","two","three") tree.column("#0", width=270, minwidth=270, stretch=tk.NO) tree.column("one", width=150, minwidth=150, stretch=tk.NO) tree.column("two", width=400, minwidth=200) tree.column("three", width=80, minwidth=50, stretch=tk.NO)

    しのtree.heading("#0",text="Name",anchor=tk.W) tree.heading("one", text="Date modified",anchor=tk.W) tree.heading("two", text="Type",anchor=tk.W) tree.heading("three", text="Size",anchor=tk.W)

    いくつかのをする# Level 1 folder1=tree.insert("", 1, "", text="Folder 1", values=("23-Jun-17 11:05","File folder","")) tree.insert("", 2, "", text="text_file.txt", values=("23-Jun-17 11:25","TXT file","1 KB")) # Level 2 tree.insert(folder1, "end", "", text="photo1.png", values=("23-Jun-17 11:28","PNG file","2.6 KB")) tree.insert(folder1, "end", "", text="photo2.png", values=("23-Jun-17 11:29","PNG file","3.2 KB")) tree.insert(folder1, "end", "", text="photo3.png", values=("23-Jun-17 11:30","PNG file","3.1 KB"))

    パッキングtree.pack(side=tk.TOP,fill=tk.X)

    Windowsでは、このからのスクリーンショットをできます。

    https://riptutorial.com/ja/home 18

  • プログレスバー

    ウィジェットttk.progressは、ユーザがプログラムがされていることをるためにいをうにです。に、0.5ごとにプログレスバーをするをします。

    プログレスバーをするdef progress(currentValue): progressbar["value"]=currentValue

    をするmaxValue=100

    プログレスバーをするprogressbar=ttk.Progressbar(master,orient="horizontal",length=300,mode="determinate") progressbar.pack(side=tk.TOP)

    プログレスバーがプログラムのにある、「」モードがされます。

    とcurrentValue=0 progressbar["value"]=currentValue progressbar["maximum"]=maxValue

    https://riptutorial.com/ja/home 19

    https://i.stack.imgur.com/2Mzp2.png

  • 0.5ごとにをエミュレートするdivisions=10 for i in range(divisions): currentValue=currentValue+10 progressbar.after(500, progress(currentValue)) progressbar.update() # Force an update of the GUI

    オンラインでTtkウィジェットをむ https://riptutorial.com/ja/tkinter/topic/10622/ttkウィジェット

    https://riptutorial.com/ja/home 20

    https://riptutorial.com/ja/tkinter/topic/10622/ttk%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88https://riptutorial.com/ja/tkinter/topic/10622/ttk%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88

  • 6: ttkスタイルをカスタマイズする

    しいttkウィジェットのスタイルは、ttkのもなの1つです。なtkパッケージとはまったくなるであることにえて、ウィジェットでなカスタマイズをすることができます。

    Examples

    ツリービューをカスタマイズする

    Treeviewなをることによって、なツリービューをカスタマイズするをすことができます。

    この、のコードでスタイル "mystyle.Treeview"をしますのをするためのコメントを。

    style = ttk.Style() style.configure("mystyle.Treeview", highlightthickness=0, bd=0, font=('Calibri', 11)) # Modify the font of the body style.configure("mystyle.Treeview.Heading", font=('Calibri', 13,'bold')) # Modify the font of the headings style.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders

    に、のスタイルをえるウィジェットがされます。

    tree=ttk.Treeview(master,style="mystyle.Treeview")

    にじてなるをするは、 tagsをできtags 。

    tree.insert(folder1, "end", "", text="photo1.png", values=("23-Jun-17 11:28","PNG file","2.6 KB"),tags = ('odd',)) tree.insert(folder1, "end", "", text="photo2.png", values=("23-Jun-17 11:29","PNG file","3.2 KB"),tags = ('even',)) tree.insert(folder1, "end", "", text="photo3.png", values=("23-Jun-17 11:30","PNG file","3.1 KB"),tags = ('odd',))

    に、たとえば、をタグにけることができます。

    tree.tag_configure('odd', background='#E8E8E8') tree.tag_configure('even', background='#DFDFDF')

    はとしのにフォントがされたツリービューであり、のとはなります。

    https://riptutorial.com/ja/home 21

    http://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-example

  • のをするには、のコードを、 TreeviewBasicのので/するがあります。

    オンラインでttkスタイルをカスタマイズするをむ https://riptutorial.com/ja/tkinter/topic/10624/ttkスタイルをカスタマイズする

    https://riptutorial.com/ja/home 22

    https://i.stack.imgur.com/Te2PD.pnghttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttp://www.riptutorial.com/tkinter/example/31880/treeview--basic-examplehttps://riptutorial.com/ja/tkinter/topic/10624/ttk%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%82%92%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/10624/ttk%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%82%92%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/10624/ttk%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%82%92%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/10624/ttk%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%82%92%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/10624/ttk%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%82%92%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/10624/ttk%E3%82%B9%E3%82%BF%E3%82%A4%E3%83%AB%E3%82%92%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA%E3%81%99%E3%82%8B

  • 7: スクロールウィジェット

    スクロールバーは、リストボックス、キャンバス、およびテキストウィジェットにできます。さらに、Entryウィジェットはにスクロールすることができます。のタイプのウィジェットをスクロールできるようにするには、それらをキャンバスまたはテキストウィジェットのにするがあります。

    スクロールバー= tk.Scrollbar、** kwargs•

    パラメーター

    パラメータ

    tkinterウィジェットはにします。ルートウィンドウをいて、すべてのウィジェットにはがあります。のオンラインチュートリアルでは、この「マスター」とばれています。ウィジェットがpack、placeまたはgridでにされると、このウィジェットがこのウィジェットのにされます

    オリエント

    "vertical" デフォルトまたは"horizontal"いずれかのスクロールバーのき

    これらのでは、tkinter import tkinter as tk tminter import tkinter as tk 3またはimport Tkinter as tk import Tkinter as tk python 2をimport tkinter as tkてインポートしたとしています。

    Examples

    テキストウィジェットへのスクロールバーの

    ウィジェットとスクロールバーののはにします。スクロールバーは、ウィジェットとじさになるようににするがあります。

    text = tk.Text(parent) text.pack(side="left") scroll_y = tk.Scrollbar(parent, orient="vertical", command=text.yview) scroll_y.pack(side="left", expand=True, fill="y") text.configure(yscrollcommand=scroll_y.set)

    https://riptutorial.com/ja/home 23

  • キャンバスウィジェットをおよびにスクロールする

    はテキストウィジェットのとにじですが、 Gridレイアウトをしてウィジェットのりにスクロールバーをします。

    canvas = tk.Canvas(parent, width=150, height=150) canvas.create_oval(10, 10, 20, 20, fill="red") canvas.create_oval(200, 200, 220, 220, fill="blue") canvas.grid(row=0, column=0) scroll_x = tk.Scrollbar(parent, orient="horizontal", command=canvas.xview) scroll_x.grid(row=1, column=0, sticky="ew") scroll_y = tk.Scrollbar(parent, orient="vertical", command=canvas.yview) scroll_y.grid(row=0, column=1, sticky="ns") canvas.configure(yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set)

    Textウィジェットとはなり、Canvasのスクロールはコンテンツがされたときににされないため、 scrollregionをしてでしてするがあります。

    canvas.configure(scrollregion=canvas.bbox("all"))

    canvas.bbox("all")は、キャンバスのコンテンツにするのをします。

    ウィジェットのグループをスクロールする

    ウィンドウにのウィジェットがまれていると、すべてがされないことがあります。ただし、ウィンドウTkまたはToplevelインスタンスもフレームもスクロールではありません。ウィンドウのをスクロールにする1つのは、すべてのウィジェットをフレームにれ、にcreate_windowメソッドをしてこのフレームをCanvasにめむことです。

    canvas = tk.Canvas(parent) scroll_y = tk.Scrollbar(parent, orient="vertical", command=canvas.yview) frame = tk.Frame(canvas) # group of widgets for i in range(20): tk.Label(frame, text='label %i' % i).pack() # put the frame in the canvas canvas.create_window(0, 0, anchor='nw', window=frame) # make sure everything is displayed before configuring the scrollregion canvas.update_idletasks() canvas.configure(scrollregion=canvas.bbox('all'), yscrollcommand=scroll_y.set) canvas.pack(fill='both', expand=True, side='left') scroll_y.pack(fill='y', side='right')

    オンラインでスクロールウィジェットをむ https://riptutorial.com/ja/tkinter/topic/8931/スクロールウィジェット

    https://riptutorial.com/ja/home 24

    https://riptutorial.com/ja/tkinter/topic/8931/%E3%82%B9%E3%82%AF%E3%83%AD%E3%83%BC%E3%83%AB%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88https://riptutorial.com/ja/tkinter/topic/8931/%E3%82%B9%E3%82%AF%E3%83%AD%E3%83%BC%E3%83%AB%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88https://riptutorial.com/ja/tkinter/topic/8931/%E3%82%B9%E3%82%AF%E3%83%AD%E3%83%BC%E3%83%AB%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88

  • 8: をラベル/ボタンにする

    これは、のなと、をしくするをしています。

    Examples

    Tkinterでサポートされているファイル

    TkinterはPILPython Imaging Library、.JPG、.PNG、.GIFの.ppmファイルをサポートしています。

    インポートしてイメージをするには、まずのようなをするがあります。

    Image = PhotoImage(filename = [Your Image here])

    、「img」コールバックをして、このイメージをButtonやLabelsにすることができます

    Lbl = Label (width=490, img=image)

    .GIFの。

    gifをするには、フレームごとにアニメーションのようにするがあります。

    アニメーションGIFは、1つのファイルののフレームでされています。 Tkはのフレームをロードしますが、イメージのにインデックスパラメータをすことで、なるフレームをすることができます。えば

    frame2 = PhotoImage(file=imagefilename, format="gif -index 2")

    すべてのフレームを々のPhotoImageにロードしてから、タイマーイベントをして、されているフレームをりえますlabel.configureimage = nextframe。タイマーのれにより、アニメーションのをできます。フレームをえたにフレームをするので、イメージのフレームをするはありません。

    オンラインでをラベル/ボタンにするをむ https://riptutorial.com/ja/tkinter/topic/9746/をラベル-ボタンにする

    https://riptutorial.com/ja/home 25

    https://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8Bhttps://riptutorial.com/ja/tkinter/topic/9746/%E7%94%BB%E5%83%8F%E3%82%92%E3%83%A9%E3%83%99%E3%83%AB-%E3%83%9C%E3%82%BF%E3%83%B3%E3%81%AB%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B

  • 9: のウィンドウTopLevelウィジェット

    Examples

    TkとToplevelのい

    Tkはアプリケーションのなルートであり、インスタンスするのあるのウィジェットであり、GUIはされるとシャットダウンします。

    Toplevelはアプリケーションのウィンドウです。ウィンドウをじると、そのウィンドウ{1}にされているすべてのウィジェットがされますが、プログラムはシャットダウンされません。

    try: import tkinter as tk #python3 except ImportError: import Tkinter as tk #python2 #root application, can only have one of these. root = tk.Tk() #put a label in the root to identify the window. label1 = tk.Label(root, text="""this is root closing this window will shut down app""") label1.pack() #you can make as many Toplevels as you like extra_window = tk.Toplevel(root) label2 = tk.Label(extra_window, text="""this is extra_window closing this will not affect root""") label2.pack() root.mainloop()

    あなたのPythonプログラムがほとんどの1つのアプリケーションをす、 Tkインスタンスは1つだけですが、きなだけくのToplevelウィンドウをすることができます。

    try: import tkinter as tk #python3 except ImportError: import Tkinter as tk #python2 def generate_new_window(): window = tk.Toplevel() label = tk.Label(window, text="a generic Toplevel window") label.pack() root = tk.Tk() spawn_window_button = tk.Button(root, text="make a new window!", command=generate_new_window) spawn_window_button.pack()

    https://riptutorial.com/ja/home 26

  • root.mainloop()

    {1}Toplevel A = Toplevel(root) がのToplevel B = Toplevel(A) のである、ウィンドウAをじるとウィンドウBもじます。

    ウィンドウスタックをする.liftメソッド

    のウィンドウをのウィンドウのにちげるもなケースは、そのウィンドウ ToplevelまたはTkいずれか.lift()メソッドをびすだけです。

    import tkinter as tk #import Tkinter as tk #change to commented for python2 root = tk.Tk() for i in range(4): #make a window with a label window = tk.Toplevel(root) label = tk.Label(window,text="window {}".format(i)) label.pack() #add a button to root to lift that window button = tk.Button(root, text = "lift window {}".format(i), command=window.lift) button.grid(row=i) root.mainloop()

    しかし、そのウィンドウがされてちげようとすると、のようなエラーがします

    Exception in Tkinter callback Traceback (most recent call last): File "/.../tkinter/__init__.py", line 1549, in __call__ return self.func(*args) File "/.../tkinter/__init__.py", line 785, in tkraise self.tk.call('raise', self._w, aboveThis) _tkinter.TclError: bad window path name ".4385637096"

    ユーザーのにのウィンドウをしようとしているが、じられているは、そのウィンドウをすることをおめします。

    import tkinter as tk #import Tkinter as tk #change to commented for python2 dialog_window = None def create_dialog(): """creates the dialog window ** do not call if dialog_window is already open, this will create a duplicate without handling the other if you are unsure if it already exists or not use show_dialog()""" global dialog_window dialog_window = tk.Toplevel(root) label1 = tk.Label(dialog_window,text="this is the dialog window") label1.pack() #put other widgets dialog_window.lift() #ensure it appears above all others, probably will do this anyway

    https://riptutorial.com/ja/home 27

  • def show_dialog(): """lifts the dialog_window if it exists or creates a new one otherwise""" #this can be refactored to only have one call to create_dialog() #but sometimes extra code will be wanted the first time it is created if dialog_window is None: create_dialog() return try: dialog_window.lift() except tk.TclError: #window was closed, create a new one. create_dialog() root = tk.Tk() dialog_button = tk.Button(root, text="show dialog_window", command=show_dialog) dialog_button.pack() root.mainloop()

    このようにして、 show_dialogはダイアログウィンドウがするかどうかをします。また、 .winfo_exists()をびして、 try:exceptでラップするわりにウィンドウをちげようとするにそれがするかどうかをべることができます。

    あり.lower()とじようにする.lift()スタックのウィンドウをげる、は

    import tkinter as tk #import Tkinter as tk #change to commented for python2 root = tk.Tk() root.title("ROOT") extra = tk.Toplevel() label = tk.Label(extra, text="extra window") label.pack() lower_button = tk.Button(root, text="lower this window", command=root.lower) lower_button.pack() root.mainloop()

    のアプリケーションのでもがっていることにづくでしょう。のウィンドウのにだけがって.lower()メソッドにすことができます。これはに.lift()メソッドをってうこともできます1。

    オンラインでのウィンドウTopLevelウィジェットをむ https://riptutorial.com/ja/tkinter/topic/6439/のウィンドウ-toplevelウィジェット-

    https://riptutorial.com/ja/home 28

    https://riptutorial.com/ja/tkinter/topic/6439/%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6-toplevel%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88-https://riptutorial.com/ja/tkinter/topic/6439/%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6-toplevel%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88-https://riptutorial.com/ja/tkinter/topic/6439/%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6-toplevel%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88-https://riptutorial.com/ja/tkinter/topic/6439/%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6-toplevel%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88-https://riptutorial.com/ja/tkinter/topic/6439/%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6-toplevel%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88-https://riptutorial.com/ja/tkinter/topic/6439/%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6-toplevel%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88-https://riptutorial.com/ja/tkinter/topic/6439/%E8%A4%87%E6%95%B0%E3%81%AE%E3%82%A6%E3%82%A3%E3%83%B3%E3%83%89%E3%82%A6-toplevel%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88-

  • 10: のwidget.afterdelay_ms、コールバック、* args•

    パラメーター

    パラメータ

    delay_ms callbackへのびしがれたミリ

    りしえられたdelay_msにびされる。このパラメータがされていない、 .afterとのをしtime.sleep ミリ

    は、 .afterがにされたメソッドによってけれられたwidgetしていwidget つまり、 widget=tk.Label(parent) 。

    Examples

    .after

    .after(delay, callback=None)は、すべてのtkinterウィジェットにしてされたメソッドです。このメソッドは、ミリでされたdelayにcallbackびしcallback 。がえられていなければ、それはtime.sleepとたようなきをしtime.sleep ただしではなくミリ

    afterなタイマーをするのをにします。

    # import tkinter try: import tkinter as tk except ImportError: import Tkinter as tk class Timer: def __init__(self, parent): # variable storing time self.seconds = 0 # label displaying time self.label = tk.Label(parent, text="0 s", font="Arial 30", width=10) self.label.pack() # start the timer self.label.after(1000, self.refresh_label) def refresh_label(self): """ refresh the content of the label every second """ # increment the time self.seconds += 1 # display the new time

    https://riptutorial.com/ja/home 29

    https://docs.python.org/3/library/time.html#time.sleephttps://docs.python.org/3/library/time.html#time.sleep

  • self.label.configure(text="%i s" % self.seconds) # request tkinter to call self.refresh after 1s (the delay is given in ms) self.label.after(1000, self.refresh_label) if __name__ == "__main__": root = tk.Tk() timer = Timer(root) root.mainloop()

    オンラインでのをむ https://riptutorial.com/ja/tkinter/topic/6724/の

    https://riptutorial.com/ja/home 30

    https://riptutorial.com/ja/tkinter/topic/6724/%E9%96%A2%E6%95%B0%E3%81%AE%E9%81%85%E5%BB%B6https://riptutorial.com/ja/tkinter/topic/6724/%E9%96%A2%E6%95%B0%E3%81%AE%E9%81%85%E5%BB%B6https://riptutorial.com/ja/tkinter/topic/6724/%E9%96%A2%E6%95%B0%E3%81%AE%E9%81%85%E5%BB%B6https://riptutorial.com/ja/tkinter/topic/6724/%E9%96%A2%E6%95%B0%E3%81%AE%E9%81%85%E5%BB%B6https://riptutorial.com/ja/tkinter/topic/6724/%E9%96%A2%E6%95%B0%E3%81%AE%E9%81%85%E5%BB%B6https://riptutorial.com/ja/tkinter/topic/6724/%E9%96%A2%E6%95%B0%E3%81%AE%E9%81%85%E5%BB%B6

  • クレジット

    S. No

    Contributors

    1 tkinterのいBillal BEGUERADJ, Bryan Oakley, Community, J.J. Hakala, j_4321, JGreenwell, Mike - SMT, Neil A., Nico Brubaker, Razik, ryneke, Tadhg McDonald-Jensen, tao, Yamboy1

    2Tkinterエントリーウィジェット

    Angrywasabi, Bryan Oakley, double_j, j_4321

    3Tkinterジオメトリマネージャー

    Henry

    4Tkinterラジオボタンウィジェット

    j_4321, nbro, Parviz Karimli

    5 Ttkウィジェット David Duran

    6ttkスタイルをカスタマイズする

    David Duran

    7スクロールウィジェット

    j_4321

    8をラベル/ボタンにする

    Angrywasabi

    9のウィンドウTopLevelウィジェット

    Tadhg McDonald-Jensen

    10 の David Duran, Neil A., Tadhg McDonald-Jensen

    https://riptutorial.com/ja/home 31

    https://riptutorial.com/ja/contributor/5906918/billal-begueradjhttps://riptutorial.com/ja/contributor/7432/bryan-oakleyhttps://riptutorial.com/ja/contributor/-1/communityhttps://riptutorial.com/ja/contributor/5781248/j-j--hakalahttps://riptutorial.com/ja/contributor/6415268/j-4321https://riptutorial.com/ja/contributor/4667934/jgreenwellhttps://riptutorial.com/ja/contributor/7475225/mike---smthttps://riptutorial.com/ja/contributor/6719703/neil-a-https://riptutorial.com/ja/contributor/6856423/nico-brubakerhttps://riptutorial.com/ja/contributor/3157961/razikhttps://riptutorial.com/ja/contributor/6713378/rynekehttps://riptutorial.com/ja/contributor/5827215/tadhg-mcdonald-jensenhttps://riptutorial.com/ja/contributor/2348704/taohttps://riptutorial.com/ja/contributor/8013876/yamboy1https://riptutorial.com/ja/contributor/7758938/angrywasabihttps://riptutorial.com/ja/contributor/7432/bryan-oakleyhttps://riptutorial.com/ja/contributor/3826759/double-jhttps://riptutorial.com/ja/contributor/6415268/j-4321https://riptutorial.com/ja/contributor/7519434/henryhttps://riptutorial.com/ja/contributor/6415268/j-4321https://riptutorial.com/ja/contributor/3924118/nbrohttps://riptutorial.com/ja/contributor/5601431/parviz-karimlihttps://riptutorial.com/ja/contributor/2726773/david-duranhttps://riptutorial.com/ja/contributor/2726773/david-duranhttps://riptutorial.com/ja/contributor/6415268/j-4321https://riptutorial.com/ja/contributor/7758938/angrywasabihttps://riptutorial.com/ja/contributor/5827215/tadhg-mcdonald-jensenhttps://riptutorial.com/ja/contributor/2726773/david-duranhttps://riptutorial.com/ja/contributor/6719703/neil-a-https://riptutorial.com/ja/contributor/5827215/tadhg-mcdonald-jensen

    約章 1: tkinterの使い方備考

    Python 2とPython 3の違いPython 2.xでのインポートPython 3.xでのインポート

    参考文献バージョンTclPythonExamplesインストールまたはセットアップこんにちは世界! (最小)こんにちは世界! (モジュラ、オブジェクト指向)

    章 2: Tkinterエントリーウィジェット構文パラメーター備考Examplesエントリウィジェットの作成とデフォルト値の設定Entryウィジェットの価値を得るエントリウィジェットへの検証の追加エントリーウィジェットからintを取得する

    章 3: Tkinterジオメトリマネージャー前書きExamplesパック()グリッド()場所()

    章 4: Tkinterラジオボタンウィジェット構文パラメーター備考Examplesラジオボタンをボタンボックスにする方法の例を次に示します。ラジオボタンのグループを作成する

    章 5: Ttkウィジェット前書き構文パラメーター備考Examplesツリービュー:基本的な例

    ウィジェットを作成する列の定義見出しの定義いくつかの行を挿入するパッキングプログレスバー

    プログレスバーを更新する機能最大値を設定するプログレスバーを作成する初期値と最大値0.5秒ごとに進化をエミュレートする章 6: ttkスタイルをカスタマイズする前書きExamplesツリービューをカスタマイズする

    章 7: スクロールウィジェット前書き構文パラメーター備考Examplesテキストウィジェットへの垂直スクロールバーの接続キャンバスウィジェットを水平および垂直にスクロールするウィジェットのグループをスクロールする

    章 8: 画像をラベル/ボタンに追加する前書きExamplesTkinterでサポートされているファイル形式.GIF形式の使用。

    章 9: 複数のウィンドウ(TopLevelウィジェット)ExamplesTkとToplevelの違いウィンドウスタックを配置する(.liftメソッド)

    章 10: 関数の遅延構文パラメーター備考Examples.after()

    クレジット