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

How to check if Shift is held during startup of a Tk / Tkinter program?

I want my Tkinter (Tk 8.6) program to behave differently when Shift is held when the program is starting up. I know how to check the state attribute in mouse and keyboard events, but my detection needs to work even when the user doesn't cause any…
Aivar
  • 6,814
  • 5
  • 46
  • 78
4
votes
3 answers

How to disable a button by a checkbox in Tkinter

I'm studying GUI for Python, and I don't know how to disable a button with a check button. Which trigger does Python use to verify if I mark the check button? Follow some code I wrote trying to do it, but without success. Sorry for my bad…
Alcides Neto
  • 43
  • 1
  • 6
4
votes
2 answers

Listbox with checkboxes Python

I want to make listbox with checkboxes in it. I made only listbox for now, but I do not know how to put checkboxes in it. And then I want to create a button , so that I can print all selected items. Can you please help me? from tkinter import…
user8965990
4
votes
3 answers

Tkinter Entry to accept Unicode text?

I have a Tkinter Entry widget and a Hungarian keyboard. When I press the ő button on the keyboard, the Entry widget displays õ. ű becomes û. (I haven't had this problem in other applications since Windows 3.1.) Edit: I do have two language settings…
marczellm
  • 1,224
  • 2
  • 18
  • 42
4
votes
2 answers

Parent/master vs. in_ in tkinter

Examine the following code: import Tkinter as tk root=tk.Tk() f1 = tk.Frame(width=200, height=200, background="red") f2 = tk.Frame(width=100, height=100, background="blue") f1.pack(fill="both", expand=True, padx=20, pady=20) f2.place(in_=f1,…
epeleg
  • 10,347
  • 17
  • 101
  • 151
4
votes
1 answer

Python tk scroll frame?

I'm creating a simple GUI app using Tkinter with Python, but I'm having problems adding a scrollbar to a single frame. The frame is visible from top to bottom on my 20" but in order to display everything on a netbook or any other low res screen it…
Fredrik
  • 1,741
  • 4
  • 24
  • 40
4
votes
1 answer

Can python installation on Mac be forced to use tcl/tk 8.6?

I'd like to know how to get the official python installation from python.org (3.6.1) for Mac to use tcl/tk 8.6. I have been using different releases of tcl/tk 8.5 with tkinter for my project's GUI and I keep running into very limiting bugs (crash on…
Sam
  • 191
  • 1
  • 7
4
votes
4 answers

why is wish opening two windows instead of one?

In Tcl/Tk, the source of file /usr/bin/wan27 #! /usr/bin/wish -f set w .main toplevel $w wm title $w "FOO" when issuing the command "wan27" from terminal (Linux/Debian/Ubuntu 10.04), it opens two windows, one with the title wan27 and the other one…
fabjoa
  • 1,615
  • 3
  • 15
  • 15
4
votes
2 answers

How do I set the values of tkinter combobox from dictionary keys

root = Tk() my_dict = {'Drosophila melanogaster':1 'Danio rerio': 2, 'Caenorhabditis elegans':3, 'Rattus norvegicus': 4, 'Mus musculus': 5, 'Homo sapiens': 6, } combobox_values =…
Armen Halajyan
  • 87
  • 1
  • 2
  • 9
4
votes
2 answers

Itemconfigure() and memory leak with tkinter

My code (see below) is supposed to display a start/stop button, a scale button to select the speed of the visualization and a canvas with many rectangles that randomly change color with time. When I run this piece of code, the memory usage increases…
gatsu
  • 237
  • 3
  • 8
4
votes
1 answer

How do you make arrow key event handlers in Ruby/Tk

In Ruby/Tk I'm am currently making a length converter but I want to be able to allow the user to either press the up or down arrow key and it will increase or decrease the number the user inputed into the Entry box. require "tk" require…
Alex
  • 109
  • 6
4
votes
2 answers

What is a good way to show different content dynamically (in Tcl/Tk)?

I have a set of radiobuttons (say, with choices 1 and 2) and need to show some widget based off of the user's choice. For example, if they chose 1, I would show them a labelframe with several radiobuttons; whereas, if they chose 2, I would show them…
Pat
  • 16,515
  • 15
  • 95
  • 114
4
votes
0 answers

How to use option key combinations in a text widget

On a Mac I can get an a-grave character by typing Option+` followed by a - voilà ! When using a text widget however, the Option+` combination causes wish to quit unexpectedly. Is there a way to get around this? Is there a binding that will take care…
Tel Monks
  • 61
  • 1
  • 3
4
votes
1 answer

Get the text of a treeview item using it's Id - Treeview Tkinter

I would like to get the display text of the treeview item subdir3 when I double click. I know 'text' is not correct as print tree.set('subdir3') prints a dictionary of columns and values and text is not part of that, but I can't find anything about…
user2242044
  • 8,803
  • 25
  • 97
  • 164
4
votes
1 answer

How to change the tk version of your Python installation?

I have just removed my old Python framework using this procedure, and I have installed Python 3.4.3 for my architecture, which appears to be i386 according to the following command uname -p, so I have downloaded and installed the following version…
nbro
  • 15,395
  • 32
  • 113
  • 196