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

Tkinter event on key release

Is there a way to make the event call on the key release, instead of press? If you use , then event.char is blank for any special key, not just return.
Ferguzz
  • 5,777
  • 7
  • 34
  • 41
4
votes
1 answer

How to bind the '+' and '-' keys is Tcl/Tk

How can I bind the + and - keys to commands in Tcl/Tk?
SIMEL
  • 8,745
  • 28
  • 84
  • 130
4
votes
2 answers

How do I display an image with ltk?

I have written code to read a windows bitmap and would now like to display it with ltk. How can I construct an appropriate object? Is there such functionality in ltk? If not how can I do it directly interfacing to tk?
Sarien
  • 6,647
  • 6
  • 35
  • 55
4
votes
3 answers

unremovable text in tkinter

here is some code: from Tkinter import * class Main(object): def __init__(self): self.console = Text(root, relief='groove', cursor='arrow', spacing1=3) self.console.insert(INSERT, '>>> ') self.console.focus_set() …
SaulTigh
  • 913
  • 2
  • 14
  • 27
4
votes
0 answers

Setting "tk scaling" in Tkinter affects widgets but not text

I'm trying to use Tk's "tk scaling" feature to zoom a GUI but it only seems to change the size of the widgets, not the text. Is it possible to use "tk scaling" with Tkinter and have it work appropriately? Here's my test…
4
votes
1 answer

How to set WM_CLASS on TkRoot in ruby

I'm trying to set the 'WM_CLASS' attribute for my ruby tk application. I've tried several ways, but I think it should work like that: TkRoot.new(class: 'Test') But that will err with: :18:in `class': wrong number of arguments…
Lord Bo
  • 3,152
  • 3
  • 15
  • 22
4
votes
2 answers

In tcl/tk child window, I can't set a default value for my entry widget

I'm a complete beginner in the tcl/tk world, but I've tried to research this one on my own, and keep coming up empty. I'm extending with a tcl/tk app that allows me to add code to spawn a child window and do what I need to in there. The problem is…
Michael La Voie
  • 27,772
  • 14
  • 72
  • 92
4
votes
2 answers

How to open Tkinter GUI on second monitor/display? (Windows)

I'd like to incorporate a way to have my GUI open on a second monitor, if available. I want to add in some type of error handling so if there is a second monitor, use it, else open on the center of the detected display. Can this be done?
4
votes
3 answers

Tkinter - Floating Window - Resize

Inspired by this question, I would like to write my own resizing function for my root window. But I just noticed that my code shows some performance issues. If you resize it quickly you can see that the window doesn't finds its height prompt as I…
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
4
votes
0 answers

Information about "Warning: no DISPLAY variable so Tk is not available" in shinyapps.io logs

I have deployed my shinyapp online and I am constantly checking my logs for possible problems. A warning message that often appears when some users connect to the platform is the following: Warning: no DISPLAY variable so Tk is not available and in…
nd091680
  • 585
  • 4
  • 15
4
votes
1 answer

Issues with tk in ipython/jupyter

I am trying to write a gui for launching from an ipython/jupyter notebook but am running into trouble using tkinter from the notebook, especially in getting the tk gui window to close gracefully. What are best practices for how to make/launch a…
4
votes
3 answers

Is there anyway to hook up Python/Tkinter to an already running Tcl/Tk app?

I work a lot on Pure Data, an app written in Tcl/Tk and C. I'd like to be able to make a python API for plugins for modifying the Tcl/Tk GUI. To do this, it seems that I would need to be able to pass the running Tk instance to python, then have…
4
votes
1 answer

tkinter canvas - extract object id from event?

Is there a way I can extract the canvas object's id from an event? For example, I'd like to add an item to a canvas, and bind to it - but if I have multiple items of them on my canvas, I need to distinguish between them. def…
trayres
  • 522
  • 2
  • 6
  • 18
4
votes
1 answer

help with changing icon of Tk window

root = Tk() w=350 h=200 # get screen width and height ws = root.winfo_screenwidth() hs = root.winfo_screenheight() # calculate position x, y x = (ws/2) - (w/2) y = (hs/2) - (h/2) root.geometry('%dx%d+%d+%d' % (w, h, x,…
S L
  • 14,262
  • 17
  • 77
  • 116
4
votes
1 answer

R tkrplot layout issue

I've got a problem with extra space being put to the right and below plots made with tkrplot in R, as below. I've tried changing hscale and vscale, but all that does is magnify/reduce the overall size of each plot, along with the extra unwanted…
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135