Skip to content
RedFantom edited this page Mar 8, 2018 · 3 revisions

mtTkinter

Welcome to the help page of mtTkinter! mtTkinter is a thread-safe wrapper around Tkinter in Python. This module was originally written by Allen B. Taylor, but has been updated for CI and Python 3 compatibility.

Installation

You can install mtTkinter in two ways. If you are on Python 2.7 or later, you can install the PyPI-package by executing pip install mttkinter, this is the preferred method. This will automatically download and install mtTkinter, and you can then import the module as follows:

import mttkinter

As the mtTkinter module modifies Tkinter in memory, there is no need to change anything else in your program. Just import it once somewhere in your program, and everything should work smoothly.

If you are using the legacy Python 2.6 or an even older version, you can copy the mtTkinter.py directly into %PYTHON%/Libs/lib-tk in order to import it as follows:

import mtTkinter as tk

Support for Python 2.6 or lower is not tested and is not guaranteed.

Usage

Because mtTkinter.py contains the following import from Tkinter import *, you can use every Tkinter widget and variable just as you normally would. Only changing the import to mtTkinter is enough to make your application work with a thread-safe UI. The mtTkinter Tk-class, which is really the only modified class in the whole module, uses a Queue.Queue object to take event calls. The modified Tk-class has two additional keyword arguments:

  • mtDebug, specifies the amount of debug output you want to see on stdout. It defaults to 0, which disables the debug printing, but you can set it up to 9, with each level in between increasing the amount of debug messages.
  • mtCheckPeriod, the amount of milliseconds between checks for out-of-thread events waiting in the Queue. Decreasing will improve GUI responsiveness, but will also consume more CPU-power. This value defaults to 10.

Development

Currently, this module is not under active development. You can fork the repository if you want, under the LGPL License and either redistribute it yourself or, if you want your additions to be added to the PyPI package mttkinter, you can create a Pull Request to get your changes into the master branch of this repository.

Clone this wiki locally