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

How to reset selection order in tkinter.Listbox?

Lets say I have window with Listbox. After inserting items to my listbox I want to move selection with down arrow key, after pressing it i see that selection moved to last item on the list. Why pressing down arrow selects last element on the list…
BPS
  • 1,133
  • 1
  • 17
  • 38
0
votes
1 answer

AttributeError: 'int' object has no attribute 'pack'

So, the thing is, I'm currently trying to make a minecraft tellraw command generator. I didn't make the menu yet, and I'm trying to display an image inside of canvas with TKinter. The canvas does display, and it does work. But when I try to print an…
0
votes
2 answers

Bind only significant keys on tk/tkinter

Can you please tell me if there's a convenient way to have a bind only on "significant" keys with tk/tkinter? So, the situation is I have a bind on a tk.Entry (because I need a callback to trigger while keys are being pressed), like…
danicotra
  • 1,333
  • 2
  • 15
  • 34
0
votes
1 answer

Tcl/Tk: get default position of resized window (and/or whether the default position is used)

I'm creating a multi-window application (cross-platform (X11, macOS, Windows), unspecified window manager), where each window corresponds to a document. When creating a new document (and thus window), the window manager should be free to put the…
umläute
  • 28,885
  • 9
  • 68
  • 122
0
votes
2 answers

Is there any way to provide tk_messagebox an input from TCL itself and not by the click of button by user?

I have a condition that triggers a tk_messageBox. Now, after staying for a period of let's say 10 seconds, I want it to disappear with an "ok" input without any click or interaction from the user. Is there a way that can be done? if…
0
votes
1 answer

Maximum number of pending tkinter after events

Is there a defined limit on the number of tkinter after events that can be pending? This number can get big if for example a worker thread posts after events faster than tkinter can process them. What happens if this limit is exceeded?
mcu
  • 3,302
  • 8
  • 38
  • 64
0
votes
1 answer

How do i set a text size of a textbox deppending what option is chosen in tkinter?

global my_frame my_frame = Frame(tab2, bg="white") my_frame.place(relwidth= 0.81, relheight= 0.8, relx=0.1, rely=0.1,) text_scroll = Scrollbar(my_frame) text_scroll.pack(side=RIGHT, fill=Y) the text entry global textbox textbox =…
Fovu
  • 71
  • 6
0
votes
1 answer

Tkinter - How To Get Tag Name from Clicking on Rectangle

I'm fairly new to programming, so appoloigise for any inconsistencies / using code incorrectly) I've seen a few similar questions and answers on this topic, however I feel like I may be missing something. I've drawn a net of a Rubiks Cube, and I…
Ryanjewbo
  • 23
  • 2
0
votes
0 answers

Create non transparent rectangle with black background in 'Toplevel' transparent window in tkinter

In tkinter it is possible to create a 'Toplevel' window, and allow it to be transparent using the following code: self._window = tkinter.Toplevel(self._tk_master) self._window.wait_visibility() self._window.wm_attributes('-alpha', 0.4) self._canvas…
0
votes
0 answers

How I can set coordinates for messagebox in tkinter without tk window

import tkinter from tkinter import messagebox from tkinter import * root = tkinter.Tk() root.geometry('600x400+500+50000') root.mainloop() messagebox.showerror("Error", "Error…
0
votes
1 answer

AttributeError: 'New_Question' object has no attribute 'Tk'

I am trying to make a simple dialog box, and keep getting an AttributeError. Here is the code: import tkinter from tkinter import ttk import tkinter.font as font import tkinter as tk from Question import * import pickle class New_Question: …
POVEY
  • 27
  • 6
0
votes
2 answers

tkinter print value from getting input fields

Hello I am trying to get information from input fields and trying to print giris.get() ,but ı cant access this one where is the problem ? I searched a lot in stackoverflow ,but none of them solved my problem from selenium import webdriver from…
0
votes
2 answers

how to make only 1 new window when a button is clicked? tkinter

I want to make a button that when clicked opens a new window (tk.toplevel), is there a way to make the button only work once, (it only makes one new window when clicked thereafter the the button when clicked does not do anything) from the below code…
coder_not_found
  • 202
  • 2
  • 13
0
votes
1 answer

In Python, how would you have a GUI up constantly, but have it constantly fetch data from database to update in real time?

The idea I want to accomplish is to have my GUI shown below to always be displayed, but to have the code below always updating and pulling from the database to update the GUI in real time as new information is added or deleted. I was thinking making…
Ness10
  • 3
  • 1
0
votes
1 answer

Is it posible to update a label in tkinter?

I made a program that could find square roots, but I noticed when finding the square root of 3 and then 4, that it didn't change the label, instead it made a new one on top of the old one (see pics). This is how my code looks: import tkinter as…