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 can I use matplotlib's mathtext rendering outside of matplotlib in another tk widget?

I know that matplotlib can render math expressions readily with, for instance, txt=Text(x,y,r'$\frac{1}{2}') which would make the fraction 1 over 2 at x,y. However, instead of placing the text at x,y I would like to use the rendered string in a…
esmit
  • 1,748
  • 14
  • 27
4
votes
1 answer

Cannot invoke button command: application has been destroyed

Given below is the code for creating independent windows using Tkinter and Python: import Tkinter Tkinter.NoDefaultRoot() win1=Tkinter.Tk() win2=Tkinter.Tk() Tkinter.Button(win1, text='Woho!',command=win1.destroy()).pack() Tkinter.Button(win2,…
praxmon
  • 5,009
  • 22
  • 74
  • 121
4
votes
1 answer

Tkinter StringVar error

Hi i get an error with this code that StringVar() is not defined, and its probably a small thing but i am not that experienced with tkinter and would like some help, thanks. Here's my code: import tkinter as tk class Converter1(tk.Tk): def…
user2992997
  • 629
  • 2
  • 6
  • 9
4
votes
1 answer

global variable issues with tkinter python

I am trying to create a simple interface to access the name array with first, last, previous and next functionality. But the global variable I am using as a position tracker is not working. I have already referred to various question. Would really…
Strommer
  • 313
  • 1
  • 2
  • 10
4
votes
2 answers

Win32::SerialPort constructor goes buffer-overflow when reference variable is given

This works well: my $PortObj; $PortObj = new Win32::SerialPort ("COM12") || die "Can't open COM\n"; However when I try to provide a variable instead of "COM12" from TK Entry, like this: my $portNumVar = "12"; my $portNum =…
Mark
  • 1,540
  • 2
  • 13
  • 21
4
votes
1 answer

Any GUI lib out there that can portably handle *not* being in the main thread?

What it says on the tin. Qt 5.x does it fine on Windows (despite the console warning message), but chokes on repainting in Linux, and apparently anything based on Cocoa (which I've never used) strangles itself if you put the GUI event loop outside…
user
  • 4,920
  • 3
  • 25
  • 38
4
votes
2 answers

tclstub issue while using homebrew to install graphviz

Homebrew quits when trying to install graphviz, CCLD libtcldot_builtin.la ld: library not found for -ltclstub8.6 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[4]: *** [libtcldot.la] Error 1 make[4]: ***…
tipanverella
  • 3,477
  • 3
  • 25
  • 41
4
votes
2 answers

Ruby + Tk command binding - scope issue?

So I have this app require 'tk' class Foo def my_fancy_function puts "hello, world!" end def initialize @root = TkRoot.new{title "Hello, world!"} frame = TkFrame.new my_fancy_button = TkButton.new(frame) do text "Press…
KTamas
  • 451
  • 2
  • 18
4
votes
3 answers

Tcl 8.6 installation issue on Mac OS X Lion

I'm trying to build 64 bit of Tcl/Tk on Mac OS X Lion. Downloading the source from source forge ./configure --enable-framework --enable-64-bit --prefix=/usr/local make sudo make install Everything works fine up to make, but with make install, I…
prosseek
  • 182,215
  • 215
  • 566
  • 871
4
votes
1 answer

Scroll a group of widgets in Tkinter

I want to make a whole column of various widgets scrollable in a Tkinter GUI, like so: Tkinter can only attach scrollbars to certain widgets, of which, frames are not included. Making a scollable column is a common practice in interfaces, and there…
Cypress Frankenfeld
  • 2,317
  • 2
  • 28
  • 40
4
votes
1 answer

An autocompleting combobox

I'm trying to extend the behaviour of ttk::combobox to make it behave like the Google search box in my browser - i.e. I'd like it to drop down automatically and limit the entries in the listbox to those which match the string that I've typed in so…
nurdglaw
  • 2,107
  • 19
  • 37
4
votes
1 answer

Matplotlib and multiprocessing RuntimeError

I'm trying to use multiprocessing and matplotlib together. I'm creating a standard Pool, adding work with apply_async and updating the GUI with apply_async's callback function, which runs on the Pool's parent process (I verified this with…
F.X.
  • 6,809
  • 3
  • 49
  • 71
4
votes
1 answer

How do I change the text colour of an active cell in a TkTable in Python?

I am using a tktable in an application I am making using the Python's tkinter module. When I select a cell and type in it the colour of the text is white, which is very hard to read. How do I change this colour to black for example. I have already…
SmileyJames
  • 97
  • 1
  • 1
  • 8
4
votes
1 answer

Check that a value is a valid color for tk tcl

I have a class with a variable that supposed to hold a color that will later be used as a color in tcl, and since its value isn't shown to the user as a string, it can hold either words, or an Hex RGB number (for example #FF00FF or "magenta"). When…
SIMEL
  • 8,745
  • 28
  • 84
  • 130
4
votes
3 answers

Tktable : could not be found in R

I try to use tcltk in R, but the package Tktable could not be found. > library("tcltk") Loading Tcl/Tk... OK > tclRequire("Tktable") [1] FALSE Warning : In tclRequire("Tktable") : the package Tcl 'Tktable' is not found When I install R…