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

Dynamically add checkboxes with tkinter in python 2.7

I want to dynamically add ckeckboxes to my gui through a premade list. How would I populate the GUI with the names in my list? They all have the same type of functionality, so that should not be an issue.
user1876508
  • 12,864
  • 21
  • 68
  • 105
4
votes
1 answer

how to exit from a pyplot loop?

I have a python program using pyplot (backend:tkagg), in which simply a matplotlib is created with some stuff in it. When I want to exit the program, I immediately call: plt.close('all') to shut it down. Strangely enough, the program dosnt…
alessandro
  • 3,838
  • 8
  • 40
  • 59
4
votes
1 answer

How to create resizable widgets with tk/tcl

I want to enable the user to change the proportions of the layout by changing the position of the borders between widgets. Just in almost every modern GUI: (Example from Matlab)
SIMEL
  • 8,745
  • 28
  • 84
  • 130
4
votes
1 answer

Compiling perl-tk with xft support on Mac OSX Snow Leopard

I am trying to compile perl-tk with XFT support on a Mac OS X 10.6.8, but running into some problems. The first is that running perl Makefile.PL XFT=1 yields the following output (in summary the freetype.h header cannot be found, and the XFT…
user335173
4
votes
1 answer

How to get a form input using Tkinter in Pygame?

I'm writing a game using Pygame, and parts of the game require data input that Tk seems to be good at. I've got some things working, but I'm finding the implementation ugly and it is becoming clear I'm not using Tkinter the way it was intended to…
ishmandoo
  • 413
  • 5
  • 10
3
votes
2 answers

Inserting a default value into tkinter Entry stops validation

I have been following the validation for Entry boxes from here. The code below is from the answer with the added condition that if the entered value is 'Q' then the program adds 'test' to the beginning of the Entry value. However once this value is…
Jdog
  • 10,071
  • 4
  • 25
  • 42
3
votes
1 answer

Python: drawing non-overlapping circles - recursion fails, 'while' works

I am creating a game, where it will ask the user to click a series of circles in numerical order. My question is between lines no. 91 and no. 110: why does the recursion logic generate circles that overlap even though I check for that condition, but…
Daniel Chen
  • 350
  • 1
  • 10
3
votes
4 answers

tkFileDialog not converting results to a Python list on Windows

I'm using the code below (Python 2.7 and Python 3.2) to show an Open Files dialog that supports multiple-selection. On Linux filenames is a python list, but on Windows filenames is returned as {C:/Documents and Settings/IE User/My…
eug
  • 1,118
  • 1
  • 16
  • 25
3
votes
1 answer

How do I build a wrapper for Tk?

Context: Windows7, optionally MinGW I'm thinking of writing a Tk interface for Lhogho. Short of reading the source of Tkinter, how does one write that kind of a wrapper? It's been done for C++, Perl, Python, Tcl and others.
bugmagnet
  • 7,631
  • 8
  • 69
  • 131
3
votes
2 answers

How to avoid globals in Perl Tk (Tkx) GUI programming using an MVC model

I have an old and very large Perl Tk GUI application that I'm refactoring to Tkx. I want to split the interface into several packages so I can build up the application UI in a modular manner. Also, I want to keep the View separate from the Model,…
LozzerJP
  • 856
  • 1
  • 8
  • 23
3
votes
3 answers

Popup Dialog in Tkinter/Python

I need to add a popup dialog box on my GUI. So, when ever I hover my mouse over a label, it should be able to show a popup( Like the type we get while hovering over a file in windows). It should also disappear as soon i move away the mouse. To…
Ani
  • 918
  • 1
  • 10
  • 25
3
votes
1 answer

Widget to Display subprocess stdout?

I have a python based tkinter script which executes some commands using subprocess module. I need to display the standard output on the GUI itself. Since I am new to tk (One week Bold :) ), I need your advice How should i proceed. I have two…
Ani
  • 918
  • 1
  • 10
  • 25
3
votes
4 answers

Pros and cons for prototyping a desktop app with Tcl/Tk

I've begun prototyping a desktop app with Tcl and intend to present the idea to some venture capitalists. Neither desktop apps nor Tcl are in vogue and so I want to be prepared to counter any objections to this technology. Below are the pros as I…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
3
votes
3 answers

What does double buffering mean in Tkinter?

I think I saw something like this on the internet: Tkinter uses double buffering to avoid flicker. What does this mean and how and where?
Module_art
  • 999
  • 2
  • 9
  • 26
3
votes
1 answer

How to embed an application in a Tk window/frame?

If it is possible to embed an application in a Tk window, would you'd please point me to the correct methods? I'm experimenting with something like: firefox -P "ToolTest" -no-remote -new-instance -private -kiosk -url "http://127.0.0.11:8000/study"…
Gary
  • 2,393
  • 12
  • 31