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
7
votes
2 answers

How to know whether a window with a given title is already open in Tk?

I’ve writen a little python script that just pops up a message box containing the text passed on the command line. I want to pop it up only when the window —resulting from a previous call— is not open. from Tkinter import * import tkMessageBox root…
Tibi
  • 530
  • 6
  • 8
7
votes
1 answer

Memory savings of Python Tkinter GUI vs PyQT

BACKGROUND: It's important to consider memory usage of applications on ARM computers like the Raspberry Pi. When programming with Python, there are several GUI choices. A couple of the most popular are QT and TK. The Raspberry Pi 2 and 3 are…
user12711
  • 693
  • 1
  • 7
  • 21
7
votes
1 answer

How to identify non-printable KeyPress events in Tkinter

I'm making an app in Tkinter using multiple Text widgets, and I'm working on undo/redo functionality, which is triggered by a KeyPress event. (I'm not using the text widget's built-in undo stack because I have non-tkinter objects which can also be…
Gbgbgb
  • 73
  • 1
  • 5
7
votes
1 answer

Why some characters can not be typed in Python's IDLE?

I don't know how to explain this, actually I'm looking for the explanation, so I'll just mention some steps to reproduce the issue. Hopefully someone will be able to understand and elaborate: Python 3.5.0 on Windows 8.1. (However this should be…
AXO
  • 8,198
  • 6
  • 62
  • 63
7
votes
2 answers

Python/tkinter - How do I get the window size including borders on Windows?

I'm trying to position my window based on with width and height of the window. On Windows, the window size reported by wm_geometry, winfo_width and winfo_height is the size of the client area, i.e. the window size without the borders. The position…
Hubro
  • 56,214
  • 69
  • 228
  • 381
7
votes
2 answers

Tkinter Menu command targets function with arguments?

I'm wondering, how would I make a Tkinter (in Python) Menu that targets a function with arguments, such as foo("what")? def foo(arg): print "Foo, %s." % arg popup = Menu() popup.add_command(label="Spam!", command=foo("spam")) # Doesn't…
Aqua the SeaWing
  • 333
  • 4
  • 16
7
votes
1 answer

How do I make a resizeable window with a sidepanel and content area?

I'm trying to do something quite standard in GUI design using Python and Tkinter, and I can't figure it out. I'm trying to make something like the following: +------+----------------------+ | | | | | …
Ken Bellows
  • 6,711
  • 13
  • 50
  • 78
7
votes
3 answers

Using tk to create a text editor

Is it possible to use tk to create a text editor that can support syntax highlighting, autocomplete and even can be later extended to be an IDE for a specific language? I found tkinter widget, but not sure if it can support that or not? I think if a…
yassin
  • 289
  • 1
  • 5
  • 14
7
votes
1 answer

Resizing window doesn't resize contents in tkinter

I'm making my first GUI application and I've run into a silly problem. Resizing the main window doesn't resize its contents and leaves blank space. I've read the TKDocs and they only say you should use sticky and column/row weight attributes but I…
Dunno
  • 3,632
  • 3
  • 28
  • 43
7
votes
2 answers

Get data out of a tcltk function

This is probably so simple I will cringe when the answer comes back but I am totally stumped. I have tried the manuals, tried searching the web, assorted examples and anything else I can think of. I am still stuck. I am trying to create a simple…
Natalie Bjorklund
  • 175
  • 1
  • 2
  • 8
7
votes
2 answers

How to draw a bitmap real quick in python using Tk only?

Here is a problem. I want to visualize a specific vector field as a bitmap. It's ok with the representation itself, so I allready have some matrix of RGB lists like [255,255,115], but I have no good idea of how to draw it on screen. So far I make…
akalenuk
  • 3,815
  • 4
  • 34
  • 56
6
votes
1 answer

Missing tk.h and tcl.h files when building VRip

I am trying to compile VRip in Ubuntu 10.04, using the site http://graphics.stanford.edu/software/vrip/guide/ as a guide. It relies on installation of Tcl and Tk -- I have acquired the latest versions of these from the synaptic package manager. When…
3lbom
  • 139
  • 1
  • 1
  • 11
6
votes
1 answer

How do you set the default font for Tk widgets

I have a Tcl/Tk app that generates many forms and would like to be able to configure the default widget fonts from a central location without having to configure each widget with the -font switch. #!/wish button .hello -text "Hello, World!"…
user101918
6
votes
2 answers

TK python checkbutton RTL

I have a checkbutton: from tkinter import * master = Tk() Checkbutton(master, text="Here...").grid(row=0, sticky=W) mainloop() Which looks like this: I tried to move the checkbutton to the other side (to support RTL languages), so it'll be…
zvi
  • 3,677
  • 2
  • 30
  • 48
6
votes
1 answer

Tkinter - Geometry management

I see and saw a lot of questions for tkinter that quite often asks not about errors in their code, but asks how do I organize my GUI. So I would like to have an answer that focus on that and help beginners to orientate them a little bit.
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54