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
10
votes
4 answers

closing tkmessagebox after some time in python

I am developing an automated attendance system where when a student scans his RFID tag, his attendance is recorded while showing a welcoming message using a tkmessagebox pop-up. The user will not have control of a mouse or keyboard and I would like…
Sean Vella
  • 113
  • 1
  • 1
  • 5
10
votes
3 answers

Is it possible to run only a single step of the asyncio event loop

I'm working on a simple graphical network application, using asyncio and tkinter. I'm running into the problem of combining the asyncio event loop with Tk's mainloop. If possible, I'd like to do it without threads, because both these libraries (but…
Lucretiel
  • 3,145
  • 1
  • 24
  • 52
10
votes
2 answers

Tkinter: windows without title bar but resizable

What I know is if I want to create a window without title bar, I can write root = Tk() ........ root.overrideredirect(1) But I would also like the window to be resizable. Is there any solution? (FYI: I am working on Windows machine,…
Dick Wong
  • 133
  • 1
  • 1
  • 8
10
votes
2 answers

What is correct: widget.rowconfigure or widget.grid_rowconfigure?

When using grid geometry manager. Let's say you have: import tkinter as tk from tkinter import ttk root = tk.Tk() root.rowconfigure(0, weight=1) root.columnconfigure(0, weight=1) ttk.Button(root, text="Hello…
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
10
votes
3 answers

Setting up TkHtml (a Tk widget) with Python

I need a simple way to render HTML pages retrieved with Requests (python-requests.org). I'm using Python 3.2 on Windows. I was using tkinter, and I found a Tk widget called TkHtml. It is described at http://tkhtml.tcl.tk/ and a DLL is downloadable…
A Coder
  • 475
  • 1
  • 6
  • 16
9
votes
3 answers

Unable to append to clipboard

Whenever I try the following in my python interpreter. I am able to copy the word hello to the command line, even after I close the interpreter from Tkinter import Tk r = Tk() r.clipboard_append(" hello ") However if I put this in a file called…
samirahmed
  • 1,219
  • 2
  • 12
  • 16
9
votes
3 answers

expect script + how to ignore strings if not appears

I write the following expect script in order to automate ssh login to remote Linux machine And run the command "cat /etc/APP_VERSION.txt file" Sometime I not asked from ssh command about- "Are you sure you want to continue connecting…
user1121951
9
votes
3 answers

Intercept event when combobox edited

I'm using a ComboBox as part of a larger GUI, written in python/tkinter. When the drop-down selection is changed, the color is updated to indicate to the user that something has changed. However, the combobox also allows the user to type in their…
Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
9
votes
5 answers

How to only close TopLevel window in Python Tkinter?

Use the Python Tkinter , create a sub-panel (TopLevel) to show something and get user input, after user inputed, clicked the "EXIT" found the whole GUI (main panel) also destory. How to only close the toplevel window? from tkinter import…
baliao
  • 171
  • 1
  • 2
  • 11
9
votes
2 answers

What to use instead of NavigationToolbar2TkAgg?

When I run the following script: import tkinter as tk import matplotlib import matplotlib.pyplot as plt import matplotlib.figure import matplotlib.backends.backend_tkagg import numpy as np def on_key_event(event, canvas, toolbar): …
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
9
votes
2 answers

tkinter - How to stop frame changing size when widget is added?

In the Page frame, I've weighted two frames inside innerFrame so that they each take up half of the screen, however, when I add a widget to one of these frames, I've used a listbox as an example as it is large, one of the frames now takes up more…
simpleguy
  • 273
  • 7
  • 18
9
votes
1 answer

ttk styling "TNotebook.Tab" background and borderwidth not working

I been playing around with TKinter trying to create a multiple tab window. When I try to style the TNotebook.Tab it ignores the options background and borderwidth, but it acknowledges foreground. What am I doing wrong? Here is the relevant part of…
Lex
  • 386
  • 1
  • 4
  • 20
9
votes
1 answer

How to create equal-width grid columns with Tkinter?

How can I force the columns in a Tkinter application window to be of equal width? The tkdocs website states as follows: The width of each column (or height of each row) depends on the width or height of the widgets contained within the column or…
Westcroft_to_Apse
  • 1,503
  • 4
  • 20
  • 29
9
votes
1 answer

Handling unicode directory and filenames in Perl on Windows

I have an encoding problem with Perl and Windows. On a Windows 7 running Perl (strawberry 5.16) and a simple TK GUI I need to open files and/or access directories with non-english characters in their name/path. For opening files I've come out with…
Kelly o'Brian
  • 415
  • 3
  • 12
9
votes
2 answers

[Python/Tkinter]How can I fetch the value of data which was set in function "event_generate"

I'm using Python 2.7.4 and new to Tkinter, and I'm stuck with the following code. I generated an event "test" and set the "data" option with a string, but an error occurred when retrieving it from event. Error -> AttributeError: Event instance has…
vicd
  • 573
  • 4
  • 10