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
14
votes
1 answer

Display directory content with tkinter Treeview widget

I am working on a program that has its own project files and inside that are like sub-files and I want to know how to use the treeview widget to display all the sub-files inside the project file, Any Ideas?
user2213550
  • 151
  • 1
  • 1
  • 5
13
votes
1 answer

Tkinter's overrideredirect prevents certain events in Mac and Linux

I am writing a program in Python with a Tkinter UI. I want to have a small window with no title bar. This window must receive keyboard input. I am not picky whether this is in the form of an Entry widget or just binding to KeyPress.…
bytesized
  • 1,502
  • 13
  • 22
13
votes
5 answers

how do I get Tkinter askopenfilename() to open on top of other windows?

I am running a script that prompts the user for a file. There is no gui except for the file browser that opens up. I have 2 options: browse for file, or select entire folder using askdirectory(). The latter opens on top of all other windows, but…
J_matts
  • 171
  • 1
  • 1
  • 4
13
votes
4 answers

Tcl/Tk examples?

Tcl/Tk is a simple way to script small GUIs. Can anyone give a nice example with a button and a text widget. When the button is pressed should a shell command be executed and the output piped to the text widget. If you have other nice and clean…
epatel
  • 45,805
  • 17
  • 110
  • 144
13
votes
5 answers

Install tkinter and python locally

I work with linux on a servies. And I don't have the root privilege. I installed the python-3.2.3 locally to "/home/sam/install_sam". when I import the tkinter module. I get the following error: ImportError: No module named _tkinter, please install…
Samuel
  • 5,977
  • 14
  • 55
  • 77
12
votes
5 answers

How to add a border for a frame in Python Tkinter

Below is my UI. I am trying to add a border for the frame. But I am not getting any information on how to add a border. How can I do it?
user2910787
12
votes
8 answers

Python Tkinter throwing Tcl error

I am learning basic GUI in Python, and I came across a sample example to read file name from file explorer on Stack Overflow. from Tkinter import Tk from tkFileDialog import askopenfilename Tk().withdraw() # we don't want a full GUI, so keep the…
charan
  • 309
  • 2
  • 4
  • 14
12
votes
4 answers

Why import * and then ttk?

My understanding is that the standard set-up for a tkinter program starts off like this: from tkinter import * from tkinter import ttk I understand that tkinter is a package, but if I've already imported all with the *, why do I still need to…
temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
11
votes
2 answers

Tkinter changing the select background color on an unfocused Text widget

I am trying to change the default background color for selected text in a Tkinter Text widget on Mac OS X when the widget does not have focus. The default unfocused select color is gray. After many hours of searching, I was unable to find an…
Jason Oster
  • 1,386
  • 1
  • 13
  • 17
11
votes
2 answers

Re-binding "select all" in Text widget

I'm working with the Text widget and I have an issue about old-school shortcuts that Tk uses. Ie: Select all: Ctrl + / vs Ctrl + a Cut: Ctrl + w vs Ctrl + x Copy: Meta + w vs Ctrl + c Paste: Ctrl + y vs Ctrl + v On Windows, all of them work except…
marw
  • 2,939
  • 4
  • 28
  • 37
11
votes
2 answers

Python - Tkinter not support MacOS Mojave Dark Mode

I have a problem with the support of Dark Mode on MacOS in python Tkinter. I used python 3.6 with ActiveTlc 8.5 and the Dark Mode works fine, the window titlebar was dark, it's fine for me... but there were some problems with the
11
votes
3 answers

Convert a C or numpy array to a Tkinter PhotoImage with a minimum number of copies

I know a recipe for displaying an MxNx3 numpy array as an RGB image via Tkinter, but my recipe makes several copies of the array in the process: a = np.random.randint(low=255, size=(100, 100, 3), dtype=np.uint8) # Original ppm_header = b'P6\n%i…
Andrew
  • 2,842
  • 5
  • 31
  • 49
11
votes
2 answers

Scaling of Tkinter GUI in 4k (3840*2160) resolution?

I use LinuxMint 17.3 Cinnamon in VirtualBox, 1920*1080 resolution is used in this machine, the Hi-DPI option is turned on. The host machine is Windows 10, with 3840*2160 resolution. Despite turning on Hi-DPI option in LinuxMint, some applications…
alr
  • 1,332
  • 3
  • 13
  • 23
11
votes
0 answers

Can't set value with tkinter/python script when using cxfreeze

I have written a program in Python with a tkinter GUI front-end. When this is run from the script there are no issues. I packaged it using cx_freeze to an exe file and running it from there works for the majority of the program. However, it has a…
Holloway
  • 6,412
  • 1
  • 26
  • 33
10
votes
2 answers

Graphical user interface with TK - button position and actions

I started using TK in python to build a graphical interface for my program. I'm not able to fix 2 issues concerning (1) the position of a button in the window and (2) use a value of a radiobutton inside a fucntion. This is my current code: root =…
user3472065
  • 1,259
  • 4
  • 16
  • 32