Ubuntu 20にTcl/TkのPythonインターフェースのtkinterをインストールしてみました。
参考サイト
tkinter — Tcl/Tk の Python インターフェース
https://docs.python.org/ja/3/library/tkinter.html
pythonプログラミングでGUIを使うためのモジュールと考えればいいのかな。
- インストール
- 確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
rootlinks@Ubuntu20:~$ sudo apt show python3-tk Package: python3-tk Version: 3.8.10-0ubuntu1~20.04 Priority: optional Section: python Source: python3-stdlib-extensions Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Matthias Klose <doko@debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 922 kB Provides: python3.8-tk, python3.9-tk Depends: python3 (>= 3.8.2-0~), python3 (<< 3.10), blt (>= 2.4z-9), libc6 (>= 2.4), libtcl8.6 (>= 8.6.0), libtk8.6 (>= 8.6.0), tk8.6-blt2.5 (>= 2.5.3) Suggests: tix, python3-tk-dbg Breaks: libpython3.6-stdlib (<< 3.6.4~rc1-2), libpython3.7-stdlib (<< 3.7.0~a3-2) Replaces: libpython3.6-stdlib (<< 3.6.4~rc1-2), libpython3.7-stdlib (<< 3.7.0~a3-2) Task: ubuntustudio-video, ubuntustudio-photography Download-Size: 104 kB APT-Sources: http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages Description: Tkinter - Writing Tk applications with Python 3.x A module for writing portable GUI applications with Python 3.x using Tk. Also known as Tkinter. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
rootlinks@Ubuntu20:~$ sudo apt install python3-tk Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-5.4.0-42 linux-headers-5.4.0-42-generic linux-image-5.4.0-42-generic linux-modules-5.4.0-42-generic linux-modules-extra-5.4.0-42-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: blt libtcl8.6 libtk8.6 tk8.6-blt2.5 Suggested packages: blt-demo tcl8.6 tk8.6 tix python3-tk-dbg The following NEW packages will be installed: blt libtcl8.6 libtk8.6 python3-tk tk8.6-blt2.5 0 upgraded, 5 newly installed, 0 to remove and 10 not upgraded. Need to get 2297 kB of archives. After this operation, 9465 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libtcl8.6 amd64 8.6.10+dfsg-1 [902 kB] Get:2 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libtk8.6 amd64 8.6.10-1 [714 kB] Get:3 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 tk8.6-blt2.5 amd64 2.5.3+dfsg-4 [572 kB] Get:4 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 blt amd64 2.5.3+dfsg-4 [4944 B] Get:5 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 python3-tk amd64 3.8.10-0ubuntu1~20.04 [104 kB] Fetched 2297 kB in 18s (128 kB/s) Selecting previously unselected package libtcl8.6:amd64. (Reading database ... 220521 files and directories currently installed.) Preparing to unpack .../libtcl8.6_8.6.10+dfsg-1_amd64.deb ... Unpacking libtcl8.6:amd64 (8.6.10+dfsg-1) ... Selecting previously unselected package libtk8.6:amd64. Preparing to unpack .../libtk8.6_8.6.10-1_amd64.deb ... Unpacking libtk8.6:amd64 (8.6.10-1) ... Selecting previously unselected package tk8.6-blt2.5. Preparing to unpack .../tk8.6-blt2.5_2.5.3+dfsg-4_amd64.deb ... Unpacking tk8.6-blt2.5 (2.5.3+dfsg-4) ... Selecting previously unselected package blt. Preparing to unpack .../blt_2.5.3+dfsg-4_amd64.deb ... Unpacking blt (2.5.3+dfsg-4) ... Selecting previously unselected package python3-tk:amd64. Preparing to unpack .../python3-tk_3.8.10-0ubuntu1~20.04_amd64.deb ... Unpacking python3-tk:amd64 (3.8.10-0ubuntu1~20.04) ... Setting up libtcl8.6:amd64 (8.6.10+dfsg-1) ... Setting up libtk8.6:amd64 (8.6.10-1) ... Setting up tk8.6-blt2.5 (2.5.3+dfsg-4) ... Setting up blt (2.5.3+dfsg-4) ... Setting up python3-tk:amd64 (3.8.10-0ubuntu1~20.04) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ... |
1 |
rootlinks@Ubuntu20:~$ python -m tkinter |
Hello World
参考サイト、そのままですが。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
rootlinks@Ubuntu20:~$ vi Hello_World.py rootlinks@Ubuntu20:~$ cat Hello_World.py import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): super().__init__(master) self.master = master self.pack() self.create_widgets() def create_widgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello World\n(click me)" self.hi_there["command"] = self.say_hi self.hi_there.pack(side="top") self.quit = tk.Button(self, text="QUIT", fg="red", command=self.master.destroy) self.quit.pack(side="bottom") def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop() |