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

hide and show frame in tcl tk gui

I want to make a frame that can be hidden and shown alternatively. The problem is Tk does not provide any hide/unpack command. I use vtcl and there is an option "Window hode" which only hides the window at top level. Now I want to hide a frame and…
user954134
  • 129
  • 2
  • 8
5
votes
3 answers

Get selected item in listbox and call another function storing the selected for it

I have a canvas that calls createCategoryMeny(x) when it is clicked. This function just creates a Toplevel() window, def createCategoryMenu(tableNumber): ##Not interesting below: categoryMenu = Toplevel() categoryMenu.title("Mesa…
Trufa
  • 39,971
  • 43
  • 126
  • 190
5
votes
1 answer

Ruby, deploying an exe with ocra that contains the TK GUI

Ocra is unable to handle applications that require 'tk' require 'tk' puts 'nope' Packing this code with ocra http://github.com/larsch/ocra doesn't work (like mentioned in one of the issues at the link) Issue:…
5
votes
4 answers

Python subprocess killing

I have problem killing sub processes. The following piece of code is used for creating the sub process- while(not myQueue.empty()): p=Popen(myQueue.get(),shell=True,stdin=PIPE,stderr=PIPE) I'm creating processes by iterating until the…
Alphaceph
  • 115
  • 1
  • 10
5
votes
1 answer

Python IDLE cannot open file, says "the open file operation failed to connect to the open and save panel service"

just upgraded to a new MBP with an m1 pro chip. I'm encountering some weird issues trying to open files through IDLE. It throws an error saying "the open file operation failed to connect to the open and save panel service" I have tried reinstalling…
TerenceA
  • 51
  • 1
  • 2
5
votes
1 answer

Where are the tk style customization saved/stored?

Take this very simple code sample: import tkinter as tk from tkinter import ttk root = tk.Tk() s = ttk.Style() s.theme_use('vista') s.map("Mod.TCombobox",fieldbackground=[('readonly', 'red')]) Can you tell me where the Mod.TCombobox…
danicotra
  • 1,333
  • 2
  • 15
  • 34
5
votes
2 answers

tkinter - define "custom colors" for colorchooser

I am currently using a colorchooser from tkinter in a project to allow the user to choose a custom colour. Minimally, this can be created (in Python 3.x) through from tkinter import colorchooser cp = colorchooser.askcolor() When this window…
asongtoruin
  • 9,794
  • 3
  • 36
  • 47
5
votes
1 answer

How to emit events in tkinter?

I have simple app written in python3 and tkinter module. I want to write my custom widget and need to send my custom event. Why this sample code below does not work? #!/usr/bin/env python3 from tkinter import * class MyWidget(Listbox): def…
BPS
  • 1,133
  • 1
  • 17
  • 38
5
votes
2 answers

tkdiff how to ignore line endings

Using tkdiff on unix platform, I've tried modifying whitespace option in the preferences window to be -w or -b, neither of which seem to ignore carriage return differences (unix/pc.) -w works with diff from the command line. Any thoughts would be…
Stew
  • 51
  • 1
  • 2
5
votes
2 answers

Tkinter splash screen & multiprocessing outside of mainloop

I have implemented a splash screen that is shown while my application loads the database from remote cloud storage on startup. The splash screen is kept alive (there's a progressbar on it) with calls to .update() and is destroyed once the separate…
Sam
  • 191
  • 1
  • 7
5
votes
1 answer

How to find the path of Tcl/Tk library that Tkinter is currently using?

TCL_LIBRARY and TK_LIBRARY environment variables can be used to bind Tkinter with proper Tcl/Tk installation. How to get the location of Tcl/Tk from working Tkinter instance? (I'm running a frontend in non-virtual Python with working Tkinter and I…
Aivar
  • 6,814
  • 5
  • 46
  • 78
5
votes
1 answer

How to locate the source file of a subroutine call when debugging a complex CPAN distribution?

I am trying to debug a Tk program for a while now. The problem seems to be with a deiconify() call from a top level window, however I am not able to locate the source file where the deiconify() sub is defined. Here is a made-up example just to…
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
5
votes
1 answer

Does Tk provide support for Wayland display protocol?

This video introduced to me the issues with X and it's replacement by the Wayland protocol. The adoption of the Wayland protocol appears to be growing over the years. My questions: Is tkinter and tcl/Tk going to comply with the Wayland protocol?…
Sun Bear
  • 7,594
  • 11
  • 56
  • 102
5
votes
2 answers

Is there a way to show the menu bar inside an application window on a Mac?

I was following a tutorial and received different results when doing exactly what was said. I want the menu bar to show up inside the actual tkinter application window like it does on the tutorial. He is using Windows. It is instead showing up on…
gmonz
  • 252
  • 1
  • 5
  • 17
5
votes
2 answers

Why are waitVariable calls not independent even if different variable ref is used?

I'm new to Tk and I'd like to know whether the issue in question is a normal Tk behavior or not. In short: I have a Perl/Tk (Tk version 804.028) script which uses two Tk::ExecuteCommand (v1.6) widgets. Such objects have an execute_command method…
TrueY
  • 7,360
  • 1
  • 41
  • 46