Questions tagged [tk-toolkit]

The Tk toolkit is a scripted GUI toolkit that is designed to be used from dynamic languages (initially Tcl, but also Perl and Python).

Overview

The Tk toolkit is a GUI toolkit that is designed to be used from dynamic languages. It was developed originally by John Ousterhout for use with Tcl, but has subsequently been evolved to be supported with many other languages (notably Perl, Python and Ruby).

Tk is a native toolkit on Windows and Mac OS X. On other Unix-based platforms, it is built directly on top of X11, and by default emulates the look traditionally associated with Motif (though this is configurable). It is recommended that newer applications use widgets from the Ttk set (where appropriate) as these use a theming engine that is more suitable for handling modern look-and-feels.

One of the key features of Tk is that its behaviors are defined almost entirely through scripting (plus a powerful event binding mechanism). This gives user code great flexibility to redefine what is happening without writing new low-level programs. The low-level drawing engine is written in C and takes care to postpone actual drawing activity until an appropriate moment (typically after all pending GUI events are processed) making Tk feel extremely responsive to user activity.

Examples

Tk is a remarkably simple toolkit. The following example shows how to create a window with the label "Hello, world". The example is in Tcl and designed to be run by the wish interpreter that comes with every tcl/tk installation:

label .l -text "Hello, world"
pack .l

Other languages are only slightly more verbose. Unlike with wish, other languages typically require you to import the tk library, create the root window, and start the event loop.

Here is the same example in Python 2:

import Tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello, world")
label.pack()
root.mainloop()

Related tags

  • - questions related to themed tk widgets
  • - questions related to the python implementation of tk
  • - questions related to the perl implementation of tk

General reference links

2482 questions
88
votes
8 answers

How do I get rid of Python Tkinter root window?

Do you know a smart way to hide or in any other way get rid of the root window that appears, opened by Tk()? I would like just to use a normal dialog. Should I skip the dialog and put all my components in the root window? Is it possible or…
Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
74
votes
8 answers

How to make a GUI for bash scripts?

I want to make some graphical dialogs for my script but don't know how. I hear something about GTK-Server or something like that. If someone knows how to link Bash with tcl/tk I also be satisfied. Please do not post something like "change to C++"…
lauriys
  • 4,652
  • 7
  • 32
  • 40
73
votes
7 answers

Cannot launch Git GUI using Cygwin on Windows

I used to launch Git GUI within my Cygwin console without any problems, but since I updated Cygwin I've got the following error message: $ git gui Application initialization failed: no display name and no $DISPLAY environment variable Error in…
Stijn Vanpoucke
  • 1,425
  • 3
  • 17
  • 30
64
votes
5 answers

Background color for Tk in Python

I'm writing a slideshow program with Tkinter, but I don't know how to change the background color to black instead of the standard light gray. How can this be done? import os, sys import Tkinter import Image, ImageTk import time root =…
olofom
  • 6,233
  • 11
  • 37
  • 50
44
votes
5 answers

TkMessageBox - No Module

import TkMessageBox When I import TkMessageBox it displays the messsge 'ImportError: No module named 'TkMessageBox'. As far as I know im using python 3.3.2 and Tk 8.5. Am I using the wrong version of python or importing it wrong ? Any answers would…
Tom Lowbridge
  • 879
  • 3
  • 9
  • 17
42
votes
4 answers

Making Tk look like a native Linux app

Browsing the TkDocs website, it looks like Tk has come a long way in the "native look and feel" department. But looking at some of these screenshots, it seems to be let down in Linux. If you scroll down that page, you'll see a Mac screenshot that…
mgiuca
  • 20,958
  • 7
  • 54
  • 70
34
votes
8 answers

Why are Tk GUI's considered ugly?

Tk GUI's seem to be universally considered ugly, but I'd like to know why specifically. Some in the Tcl/Tk world would argue that this is a moot point as there is much better support now for native look and feel, which is a big reason I decided on…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
28
votes
7 answers

Removing the TK icon on a Tkinter window

How to remove tkinter icon from title bar in it's window
Evan Fosmark
  • 98,895
  • 36
  • 105
  • 117
28
votes
7 answers

No matching distribution found for tkinter

I am stuck with this issue since last two days and I have tried every possible solution on the stack and github. It will be really great if someone can recommend. I am working with python 2.7 in a virtual environment on CentOS Linux release…
AnkP
  • 631
  • 2
  • 9
  • 18
26
votes
1 answer

Tkinter OpenGL context in Python

I need to create an OpenGL context in Tkinker, for using it with PyOpenGL Python module. Tkinker doesn't natively support OpenGL context, but I found this page on PyOpenGL docs, explaining how to use a wrapper included in the module for…
FeliceMente
  • 263
  • 1
  • 3
  • 8
25
votes
3 answers

How do I link the ActiveState distribution of Tcl/Tk to HomeBrew installed Python

I am using macOS 10.12.1 Sierra. I am using Python 2.7.12 installed with brew install python but the IDLE gives the warning WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable. Visit http://www.python.org/download/mac/tcltk/ for current…
Tom Burrows
  • 2,225
  • 2
  • 29
  • 46
25
votes
1 answer

How to update Tcl/Tk in Python?

Tcl and Tk in their version 8.6 have been out now for about six weeks. However, the files that can be downloaded from Tcl have a different folder structure and lack some files such as tk85.lib (or tk86.lib now) compared to the Tcl folder in…
Michael Westwort
  • 914
  • 12
  • 24
24
votes
5 answers

Python embeddable zip: install Tkinter

Python embeddable zip comes without pip and Tkinter. It is easy to install pip with get-pip.py in the embeddable zip. How can we install Tkinter too (assuming we do not have an existing Python installation in the same machine)?
antonio
  • 10,629
  • 13
  • 68
  • 136
23
votes
2 answers

Using Tk with C

I’m a C programmer with no desire to deal with C++ tool-kits, and I’m trying to build a simple graphical card game. I’m programming under Linux, but I’d like to have the option of a Windows port. From what I’ve read, my options are GTK+ and…
J. C. Salomon
  • 4,143
  • 2
  • 29
  • 38
23
votes
2 answers

How to implement the MVC-pattern in Tkinter

I need a basic example where MVC pattern is used with Python TK. I have some code using Tkinter, however I would like to transform it using the MVC pattern.
user618677
  • 4,909
  • 6
  • 23
  • 24
1
2 3
99 100