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

Stop multiple windows from opening with one button

Have a button to open a new window in my code, and have been trying to make the button open a new window called newest_release_window with two things in mind: If newest_release_window is not open, open the window. If newest_release_window is open,…
6
votes
2 answers

Python tkinter.filedialog askfolder interfering with clr

I'm mainly working in Spyder, building scripts that required a pop-up folder or file Browse window. The code below works perfect in spyder. In Pycharm, the askopenfilename working well, while askdirectory do nothing (stuck). But, if running in debug…
Itzik Kaplan
  • 63
  • 1
  • 6
6
votes
5 answers

How to disable manual resizing of Tkinter's Treeview column?

Since I can't horizontally scroll Treeview column due to what appears to be Tk/Tkinter limitation, I want to make it sticky so it is attached to the frame. The issue is that user can manually resize Treeview column which can mess up my interface in…
Doom8890
  • 435
  • 3
  • 15
6
votes
1 answer

tkinter frame: fix frame height when changing its content

I am working on a self written simulation tool with a appropriate GUI. In general there are two main user modes. In the first one the user can enter several values for the desired calculation. After all calculations finshed, the user can switch to…
albert
  • 8,027
  • 10
  • 48
  • 84
6
votes
2 answers

Python/Tkinter: expanding fontsize dynamically to fill frame

I know you can get frame widgets to expand and fill all of the area available to them in their container via these commands: frameName.pack(fill = 'both', expand = True) What would do the same for a text's font size? Currently my text is an…
AllTradesJack
  • 2,762
  • 5
  • 25
  • 36
6
votes
1 answer

Using Tcl/Tk how do i put the menu at the top of the screen in Ubuntu Unity?

I have a simple Tcl script that creates a window with a menu. #! /usr/bin/tclsh package require Tk # Create the main message window message .m -text {Hello Tcl!} -background white pack .m -expand true -fill both -ipadx 100 -ipady 40 # Create the…
Gary Willoughby
  • 50,926
  • 41
  • 133
  • 199
6
votes
1 answer

Limiting scroll bar length

I am trying to create a simple notepad like GUI using Perl Tk. I have used the Scrolled widget to create a Text widget with two scrollbars - one on the right and one on the bottom. The place where the two scrollbars meet looks like this: However I…
Liam Willis
  • 661
  • 6
  • 17
6
votes
3 answers

Ruby require 'tk' yields LoadError: no such file to load -- tk

I'm not able to get ruby to require 'tk' successfully. I'm using rvm, ruby 2.0.0, ActiveTcl-8.6, and Ubuntu 12.04 LTS. I have run wish provided with ActiveTcl and it seems to be working. I've looked on the RVM site http://rvm.io/integration/tk and…
6
votes
2 answers

Python Tkinter wrap widgets in frame if they reach the end of the screen

Is there something like pack to new line for Tk geometry manager? I am using pack to put widgets inside of a frame. On a high resolution screen, the widgets fit find side by side. However, if you put it into a smaller screen, the widgets will run…
jwillis0720
  • 4,329
  • 8
  • 41
  • 74
6
votes
2 answers

Add tkinter's intvar to an integer

I'm having some trouble adding a value taken from an Entry box and adding it to an existing number. In this case, I want the value of the "change speed" box to be added to the robots current speed. When run, my code produces an error: TypeError:…
JShell
  • 624
  • 2
  • 7
  • 22
6
votes
4 answers

Understanding 'gslider' function to make interactive plots

I am trying to create an interactive histogram in R whose bin width can be adjusted either by moving a slider or entering a value in the text box. In addition to this, I would also like to provide the user with an option of saving the plot for a…
tejas_kale
  • 593
  • 2
  • 7
  • 21
6
votes
2 answers

How do I create a Tiling layout / Flow layout in TkInter?

I want to to fill my window with, say, labels and I want them to wrap once the column would be bigger than the current window (or rather parent frame) size. I've tried using the grid layout, but then I have to calculate the size of the content of…
devsnd
  • 7,382
  • 3
  • 42
  • 50
6
votes
1 answer

tkinter/py2app created application doesn't show window on initial launch

I'm running into an issue where launching a python app created with Tkinter and packaged by py2app doesn't show the application window immediately. The only way I've gotten the window to show after launch is to click on the application icon in the…
vpaterno
  • 442
  • 3
  • 14
5
votes
3 answers

How do I bring an R Tk window to the front after launching via Rscript from another application?

I have a script along the lines of: if (!require(tcltk2)) {install.packages('tcltk2', repos="http://cran.us.r-project.org"); require(tcltk2)} base <- NULL done <- tclVar(0) quasitelgui <- function(inputfile = NULL) { base <- tktoplevel() …
Matt Chambers
  • 2,229
  • 1
  • 25
  • 43
5
votes
2 answers

catch clicks on the 'x' button using Tk Tcl

I'm using Tcl/Tk to build a GUI, for Linux environment and I saw that it's possible to "catch" a press on the 'x' button of the window (The button on the top right corner that closes the program). How can I catch those events?
SIMEL
  • 8,745
  • 28
  • 84
  • 130