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

The Simplest Steps to Converting TCL TK to a Stand Alone Application

After running into major compatitiblity problems with C#, ASP.NET, MS Access, Linux, and Mono, I've decided to program in a language that is cross-platform, open source, and compatible with embedded databases that are also compatible with many…
DFM
  • 473
  • 4
  • 15
22
votes
11 answers

Tkinter error: Couldn't recognize data in image file

I'm trying to put a jpg image to a tkinter canvas. tkinter gives me this error: couldn't recognize data in image file I use the code from the documentation: canv = Canvas(root, width=80, height=80, bg='white') canv.grid(row=2, column=3) img =…
Igor234
  • 359
  • 1
  • 3
  • 11
22
votes
3 answers

Expand Text widget to fill the entire parent Frame in Tkinter

I got this Text widget, and I'd like for it to expand and fill its entire parent, using the Grid geometry manager. According to the examples I've seen, this sample program should work, alas it doesn't, when expanding the window, the contents are not…
SoManyGoblins
  • 5,605
  • 8
  • 45
  • 65
21
votes
2 answers

What does calling Tk() actually do?

I was brushing up on Tkinter when I looked upon a minimal example from the NMT Tkinter 8.5 Reference. #!/usr/bin/env python import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): …
Doktoro Reichard
  • 577
  • 1
  • 7
  • 22
21
votes
3 answers

How to change font and size of buttons and frame in tkinter using python?

This is the code that i used to generate a simple text box and a button in tkinter. What should be the parameters to have a better look of the frame and buttons? root = Tk.Tk() def submit(): query = entry.get() retrieve(query) entry =…
Abkb
  • 271
  • 2
  • 3
  • 6
19
votes
5 answers

Is Tkinter worth learning?

I generally make my desktop interfaces with Qt, but some recent TK screenshots convince me Tk isn't just ugly motif any more. Additionally Tkinter comes bundled with Python, which makes distribution easier. So is it worth learning or should I stick…
hoju
  • 28,392
  • 37
  • 134
  • 178
18
votes
5 answers

from matplotlib.backends import _tkagg ImportError: cannot import name _tkagg

While trying to run this example to test how matplotlib works with Tkinter, I am getting the error: (env)fieldsofgold@fieldsofgold-VirtualBox:~/new$ python test.py Traceback (most recent call last): File "test.py", line 7, in from…
QPTR
  • 1,620
  • 7
  • 26
  • 47
18
votes
3 answers

tkinter enable/disable menu

I need some help in this. I want the user to login ... once he is logged in, only the menu corresponding to the module he is allowed to access will be enabled. So, I need to disable all the menus (except File and Help) in the beginning.. and I need…
mlwn
  • 1,156
  • 1
  • 10
  • 25
18
votes
11 answers

Hidden Features of TCL/TK

I've been working with TCL/TK ,recently started to use TCL/TK with my automation applications and I'm hungry for knowledge. To continue with the long line of Hidden Feature questions, I would like to know any hidden or handy features of TCL/TK or…
joe
  • 34,529
  • 29
  • 100
  • 137
17
votes
3 answers

Should I use Perl/Tk, Tcl::Tk or Tkx for a Perl GUI?

I really like Perl/Tk, but have come to the opinion that it's DOA. I think Tcl::Tk and Tkx are better solutions. Assume I drop Perl/Tk. Is the "most supported" route to go with Tcl::Tk (which hasn't been updated since 2007, and whose author…
xcramps
  • 1,203
  • 1
  • 9
  • 9
16
votes
2 answers

Why do Tkinter's Radio Buttons all Start Selected When Using StringVar but not IntVar?

Here is some example code that creates 4 Radiobuttons, 2 using int and 2 using str: from tkinter import * class test: def __init__(self): wind = Tk() frame1 = Frame(wind) frame1.pack() self.v1 = IntVar() …
Whud
  • 714
  • 1
  • 6
  • 19
15
votes
1 answer

Perl Tk app sometimes crashes after exceeding 4GB ram usage

I have a Perl Tk GUI application that sometimes crashes after it exceeds 4GB of RAM usage. I can exceed 4GB of RAM usage in some cases using Perl Tk, and I have no issues exceeding 4GB when running tests in a console application. Operating system:…
15
votes
4 answers

Why are multiple instances of Tk discouraged?

Consider below example: import tkinter as tk root = tk.Tk() root.title("root") other_window = tk.Tk() other_window.title("other_window") root.mainloop() and also see below example that creates instances of Tk back-to-back instead of at once, so…
Nae
  • 14,209
  • 7
  • 52
  • 79
15
votes
7 answers

Error ".onLoad failed in loadNamespace() for 'tcltk'"

I have a general question about how to effectively load any kind of external package into R. I have found that many sources detailing this information are simply insufficient, but I will leave out mentioning those respective URLs. I have…
warship
  • 2,924
  • 6
  • 39
  • 65
14
votes
3 answers

Inertial scrolling in Mac OS X with Tkinter and Python

I am working on a Python 3.3 project that uses Tkinter as a Window manager. I have mouse scroll wheel events set up for a canvas. The scrolling works in Windows 7, 8, and Ubuntu, but upon scrolling with a Magic Mouse in Mac OS X Mountain Lion, the…
neptune798
  • 141
  • 1
  • 3