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
5
votes
1 answer

Making a node in Tkinter Treeview unselectable

I would like to know , how to make certain nodes in a Treeview object un-selectable, i.e. when clicked on such a node,the node shouldn't highlight. I am working on Python 3.3/2.7 Tkinter
5
votes
3 answers

How to make Tkinter columns of equal width when widgets span multiple columns?

In the following, the buttons labelled 'ONE', 'TWO', and 'THR' do not get evenly spaced out. It seems to me that the root of the problem is that Tk is assuming a default minimum width for any column containing part of a widget that spans multiple…
Westcroft_to_Apse
  • 1,503
  • 4
  • 20
  • 29
5
votes
2 answers

Is it possible to change width of notebook tab?

As the title says, I was wondering if it's possible to change the width of a notebook widget tab? What I'm trying to do is to make sure that the tabs are of equal size and fill the entire width of the window even when someone resizes it. Currently,…
Jerry
  • 70,495
  • 13
  • 100
  • 144
5
votes
1 answer

How to stop MainLoop in Perl/Tk + AnyEvent

I'm writing Perl/Tk program which uses AnyEvent's timer. And I have a problem with closing window if timer is active. I made this window close handler: $self -> {window} -> protocol( 'WM_DELETE_WINDOW' => sub { …
michaeluskov
  • 1,729
  • 7
  • 27
  • 53
5
votes
1 answer

AttributeError when trying to use tkFont

When I run this code: from Tkinter import * import tkFont class Statify(): def __init__(self): ### Broken self.titleFont = tkFont.Font(family='Helvetica', size=24, weight='bold') self.option_add(*Label*font,…
insiduoustek
  • 53
  • 1
  • 6
5
votes
1 answer

How to make matplotlib:pyplot resizeable with the Tkinter window in Python?

I am trying to build a grid of frames in each there is a matplotlib figure. When I resize the window the figure remain with fix size and are not resizing to fit the empty space. Is there a way to make the figure change its size according to the…
Hanan Shteingart
  • 8,480
  • 10
  • 53
  • 66
5
votes
1 answer

TclTk library issue while install Rcmdr package on MacBookPro

I get the following ERROR while trying to load Rcmdr for R on my MacBook Pro: > library("Rcmdr") Error : .onLoad failed in loadNamespace() for 'tcltk', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object…
tipanverella
  • 3,477
  • 3
  • 25
  • 41
5
votes
1 answer

Tk/Tkinter: Detect application lost focus

I am making a Tkinter application. In the application, I want to pop up a context menu, which I do using Tk.Menu.post(). I don't know how to make this menu disappear when the application loses focus. I need to do this because the menu stays on…
jgoeders
  • 1,886
  • 19
  • 25
5
votes
2 answers

tk, tcl exec stderr, stdout separately

I have a tcl script. The problem is that I have to call a script that can write something to stderr (it's not a critical failure). I would like to capture stderr and stdout separately in tk/tcl. if { [catch {exec "./script.sh" << $data } result] }…
Egon
  • 1,705
  • 18
  • 32
5
votes
1 answer

Interactive Charts in Tcl/Tk

BLT is the best choice I know. It works, but the style is a little bit outdated. And i suppose it's out of maintenance? Since the lastest 2.4z was release in 2002. Plotchart is another great chart library which is part of tklib and already builin in…
Alec
  • 1,178
  • 5
  • 20
5
votes
2 answers

Tcl/tk Button - How I can pass a variable on the command option?

I have a problem passing variables on the command option, for example: package require Tk wm withdraw . destroy .button toplevel .button # button.0: puts 0 set count 0 button .button.$count -text $count -command {puts $count} grid .button.$count…
milarepa
  • 759
  • 9
  • 28
5
votes
1 answer

Why is the Tk canvas so slow?

I wrote cellular automaton (Conway's Game of Life) using Perl and TK, just for fun and practice. It works fine with console output. When I use TK, in first version I just delete and add new cells (rectangles), and after about 100 steps my program…
spyder
  • 470
  • 10
  • 22
5
votes
2 answers

Why does the Tkinter canvas request 4 extra pixels for the width and height?

>>> import Tkinter >>> c = Tkinter.Canvas(width=100, height=100) >>> c.winfo_reqwidth() 104 >>> c.winfo_reqheight() 104 The results are the same if I set borderwidth to zero. I can't find the setting or property that explains or controls these 4…
ubershmekel
  • 11,864
  • 10
  • 72
  • 89
5
votes
3 answers

Add a popup text box within an R script using tcltk

I have a long-ish script to do some data analysis, and it has to connect to several databases. One of the databases tends to update my password more frequently than I like, so I'd like to add a popup box for me to enter my current password. I…
PaulHurleyuk
  • 8,009
  • 15
  • 54
  • 78
4
votes
1 answer

GUI application using Tkinter - Drag and Drop

I have recently been using WxPython to create a GUI Network simulator like Cisco packet tracer but if I am honest it has been extremely difficult trying to find examples of what I need etc etc. Iv resorted back to the old faithful Tk. My program…