Tkinter

From Gentoo Wiki
Jump to: navigation, search

Tkinter (tkinter in Python 3.x) claims to be "most portable GUI toolkit for Python"[1] and is Python's "de-facto standard GUI (Graphical User Interface) package"[2]. Although there are several other graphical toolkits for Python, Tkinter is the one most often used in GUI development with Python.

Installation

USE flags

USE flags for dev-lang/tk Tk Widget Set

aqua Include support for the Mac OS X Aqua (Carbon/Cocoa) GUI
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
threads Add threads support for various packages. Usually pthreads
truetype Add support for FreeType and/or FreeType2 fonts
xscreensaver Add support for XScreenSaver extension

make.conf

On Gentoo, getting Tkinter can be accomplished by directly emerging the package and/or by modifying your system's use flags. Since Tkinter is build on tcl and tk, both of which are closely related to Python, you can get the package by updating your system's global use flags and re-emerging Python. Using this method of installation will pull the packages needed to successfully run Tkinter.

First, modify make.conf:

FILE /etc/portage/make.confAdd tc to the system's global USE flags:
USE="tk"

Emerge

Finally, re-emerge Python using this command:

root #emerge --ask --oneshot --newuse $(qlist -ICSe dev-lang/python)

That is it! Tkinter should now be installed.

Usage

When attempting to use Tkinter in Python code, depending on the version(s) of Python are currently installed on the system, import Tkinter might need performed in different ways:

  • When using Python 2.x.: use import Tkinter
  • using Python 3.x: use import tkinter (note the lower case T).

External Links