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

Using Matplotlib with TKAgg or Qt5Agg backend on 4K screen

I'm using Matplotlib 2.0 with Python 3.6 on Ubuntu 16.04 to create plots of data. The computer monitor is 4k resolution at 3840x2160. Plot figures appear really small with tiny font: I have tried the TKAgg and Qt5Agg backends for Matplotlib but the…
wigging
  • 8,492
  • 12
  • 75
  • 117
5
votes
1 answer

Enable mouse wheel in Spinbox Tk Python

I was wondering if there is a smart way of enabling the mouse wheel in the Tk widget 'Spinbox' in Python. The only sensible solution I found so far was to derive a new spinbox class with the wanted functionality: class Spinbox(tk.Spinbox): def…
norok2
  • 25,683
  • 4
  • 73
  • 99
5
votes
1 answer

Is it possible to get tkinter messagebox icon image files?

I'm developing a python/tkinter application, and finding the default messagebox lacked flexibility, I programmed my own using Toplevel. I was rather successful in recreating the messabox appearance, however, I could not find a way to obtain the…
dlesbre
  • 357
  • 3
  • 9
5
votes
1 answer

Installing tk/tcl on an existing ruby 2.2 installation in ubuntu 14.04

I saw some fix for previous versions of ruby, unfortunately, it doesn't work anymore for 2.2... Is there a way to add it up to my existing installation, or should I do a reinstall so I can configure ruby to include tk/tcl? Anyways, I'm using rbenv…
5
votes
1 answer

Substitute for tkinter.dooneevent

I am porting a program (VMD, Visual Molecular Dynamics), which is written in C++ and has both Python and TCL interpreters embedded, to Python 3.x. Most of its UI is hard coded using the TCL/TK framework and OpenGl, so UI refreshs are done manually.…
Caio S. Souza
  • 141
  • 3
  • 11
5
votes
1 answer

Tkinter Frame Doesn't Fill Remaining Space

This is my first encounter with Tkinter, and I'm beating my head against a wall over this. Ultimately, I am wanting a layout that uses a Frame along the left edge that contains a stack of buttons (navigation). This should be hard-wired to 100 px…
Foswick
  • 149
  • 1
  • 3
  • 12
5
votes
1 answer

How do you get the children of a Tk Widget?

How do tell a Tk widget to tell me what (or who as the case may be) its children are? Is there a command for this? For example given a canvas widget .cvs with a label, a button and other adornments ... How do interrogate the canvas?
Xofo
  • 51
  • 2
5
votes
1 answer

Create and use a new ttk::notebook tab style

I know we can modify the default style of a ttk::notebook tab using the following method : ttk::style configure TNotebook.Tab -background red My question is : is it possible to assign a custom style to individual tabs? Bascially, I would like…
user43791
  • 284
  • 2
  • 10
5
votes
1 answer

Can I use Tk in C++?

I know that probably the most popular GUI framework for C++ is Qt. But was wondering if I can use something simpler, like Tk? Cant find any references, tutorials or info about it.
FirstTimer12
  • 97
  • 2
  • 4
5
votes
8 answers

Tkinter.PhotoImage doesn't not support png image

I am using Tkinter to write a GUI and want to display a png file in a Tkiner.Label. So I have some code like this: self.vcode.img = PhotoImage(data=open('test.png').read(), format='png') self.vcode.config(image=self.vcode.img) This code runs…
zsrkmyn
  • 547
  • 1
  • 5
  • 20
5
votes
1 answer

gitk "package require Tk"

On Starting gitk from CLI on ubuntu I m getting this error vihaan@Trojan :~$ gitk application-specific initialization failed: unknown color name "S_base3" Error in startup script: unknown color name "S_base3" (database entry for "-background"…
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
5
votes
2 answers

Why does Tkinter text widget "lags" updates for increased window heights?

I'm currently implementing a sample UI for neovim, and decided to use Tkinter/python due to the popularity/simplicity of the platforms. The problem I'm having is that tkinter seems to "stack" UI updates when the window height crosses a certain…
Thiago Padilha
  • 4,590
  • 5
  • 44
  • 69
5
votes
3 answers

How to change Motif theme in DDD and Insight to something more pleasant?

I have Tk version 8.5.3 installed, theming engine support added since 8.5. Still, I don't know how to use themes, default Motif is just ugly: Screenshot
sph
  • 51
  • 1
  • 2
5
votes
1 answer

How do I disable all the user input widgets (buttons,entries..) from a parent widget?

I am designing a GUI using Python and Tkinter. All the buttons and entries required to register the user input commands are placed inside a main frame and are their child widgets. I want to know if it is possible to disable all the input…
zml
  • 617
  • 7
  • 14
5
votes
0 answers

How to receive/handle multitouch input in Tcl/Tk?

My goal is to be able to use my laptop's touchscreen as an input device for my desktop. My ideal course of action would be to run a fullscreen Tk program on the laptop and receive touchscreen input into it, and use sockets to forward that data to…
guest
  • 61
  • 4