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

tk entry background color change in readonly mode

Hi I have a requirement where i need to create table and the cells would be readonly. But along with readonly mode, the cells need to have colored background. Now with the given options, i tried doing something like below but with no luck. Since I…
Puneet Mittal
  • 532
  • 1
  • 15
  • 24
4
votes
1 answer

How do I best handle a needed patch for Perl/Tk?

I am making a change to Perl/Tk for an application that has its own resident Perl and modules installation (so we can drop the app in and go). I've found a problem I am experiencing that I just stumbled on what seems to be the patch I need here:…
Streamline
  • 2,040
  • 4
  • 37
  • 56
4
votes
1 answer

Padding specified in style ignored by Ttk Frame

The following code works as expected, presenting a red background button (with lots of padding) in a green background frame (also with lots of padding). Note that Frame padding is specified both in the Style statement and the ttk.Frame…
David Eklund
  • 182
  • 1
  • 6
4
votes
1 answer

Separating Tkinter UI concerns from Logic in Python app

This is my first app ever. It is working well but I would like to separate the UI concerns like getting input and creating labels, from the translation logic. I would then like to remove the output from the previous translation, i.e., only showing…
4
votes
3 answers

get default background of ttk.Frame

I combined a scrollbar with a ttk notebook by adapting this example and additionally porting it to Python3. I am using ttk widgets as often as possible to get a more 'modern' UI. However, there is no ttk canvas widget, so I used the standard tkinter…
albert
  • 8,027
  • 10
  • 48
  • 84
4
votes
1 answer

access widget by Tk widget/window path name

I am using validatecommand to observe and validate the input of an entry widget 'dynamically'. The standard usage of validatecommand prevents invalid characters from being entered to the observed entry widget. This is not the behaviour I like to…
albert
  • 8,027
  • 10
  • 48
  • 84
4
votes
1 answer

Python Tkinter Tk root.after Delay

I'm trying to do a chess clock using tkinter, and to do so i'm using the root.after method from the class Tk of tkinter. When the program starts, it runs really well, but after a while the clock start to get slower and slower, but if i start shaking…
4
votes
3 answers

TKinter leaving borders around widgets

When I put a button in on a colored background TKinter leaves this weird white box around the widget. For example the code below: from Tkinter import * root = Tk() root.geometry("300x100+300+300") root.configure(bg="red") button = Button(root,…
lemiant
  • 4,205
  • 4
  • 31
  • 38
4
votes
1 answer

How can I match background colors for a Frame in a Notebook for ttk/Tkinter on a Mac?

While working on a Tkinter + ttk based GUI on my Mac, I noticed a problem with background colors and the Notebook widget. When adding a ttk.Frame as a ttk.Notebook tab, the displayed background of the frame does not match the 'inset' background for…
josePhoenix
  • 538
  • 1
  • 5
  • 14
4
votes
1 answer

Error while Installing Wordnet-3.0 on ubuntu: Can't find Tcl configuration definitions

I downloaded Wordnet-3.0 and as it says tcl and tk must already be installed. So I checked this using following: vidyasagar@vidyasagar-ThinkPad-Edge-E431:~/Documents/NLP/WordNet-3.0$ dpkg -s tcl Package: tcl Status: install ok installed Priority:…
4
votes
3 answers

How do pass arguments to subroutines in Perl/Tk?

I have designed one sign-up form,in this form after getting all necessary values I will click submit button. And while clicking that submit button I want to call one function and I want to pass the arguments to that function. I have written code for…
kiruthika
  • 2,155
  • 7
  • 26
  • 33
4
votes
1 answer

Are there any bindings between .NET and TK

It would be interesting/nice to have something portable like TK to be used in Windows and in Linux with Mono like TK. Does anyone know of any bindings? or What would be a good place to start in creating bindings.
maxfridbe
  • 5,872
  • 10
  • 58
  • 80
4
votes
2 answers

Force upper case input in Tcl/Tk entry field

I've got a Tcl/Tk window with an entry box in which I'd like to force upper case character entry. That is, if any letters are typed I'd like them to appear in upper case in the entry field, instead of simply rejecting any lowercase input. I've…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
4
votes
2 answers

Call subroutine automatically whenever cursor position changes in a Text widget

I am using the Tk::Text module. I want that whenever the user changes the position of the cursor inside the Tk::Text module, it should act as a trigger to call a subroutine which I have written. How do I go about implementing this? EDIT: As answered…
Liam Willis
  • 661
  • 6
  • 17
4
votes
1 answer

Tkinter checkbutton.select() not working on Checkbutton (Python 3)

I am writing a program which reads data form a file, and adjust the settings accordingly. This is how I created the checkbutton: should_auto = BooleanVar() autodetect = Checkbutton(root, text="Autodetect", var=should_auto, onvalue = True,…
user3315473
  • 183
  • 2
  • 7