Questions tagged [tkinter]

Tkinter is the standard Python interface to the "tcl/tk" graphical user interface toolkit. In Python 3, the name of the module changed from Tkinter to tkinter.

Tkinter is the standard Python interface to the tk/tcl graphical user interface (GUI) toolkit. Tkinter runs on most operating systems, making it easy to create rich, cross-platform desktop applications with Python.

, the toolkit upon which Tkinter is based, is a mature, robust toolkit that has its roots in the language, but which can be used with many modern languages including , , and others. Tk provides a native look and feels in most operating systems. For more information about the cross-platform and cross-language features of tk visit tkdocs.com.


Icon

enter image description here


Install tkinter for Python

  • for Linux machines

apt-get install python-tk

Works on Debian-derived distributions like for Ubuntu; refer to your package manager and package list on other distributions.

  • for Windows machines

Tkinter (and, since Python 3.1, ttk) are included with all standard Python distributions. It is important that you use a version of Python supporting Tk 8.5 or greater, and ttk. We recommend installing the "ActivePython" distribution from ActiveState, which includes everything you'll need.

In your web browser, go to Activestate.com, and follow along the links to download the Community Edition of ActivePython for Windows. Make sure you're downloading a 3.1 or newer version, not a 2.x version.

Run the installer, and follow along. You'll end up with a fresh install of ActivePython, located in, e.g. C:\python32. From a Windows command prompt or the Start Menu's "Run..." command, you should then be able to run a Python shell via:

% C:\python32\python

This should give you the Python command prompt. From the prompt, enter these two commands:

>>> import tkinter
>>> tkinter._test()

This should pop up a small window; the first line at the top of the window should say "This is Tcl/Tk version 8.5"; make sure it is not 8.4!

  • for MacOS machines:

If you are using a Python from any current python.org Python installer for macOS (3.8.0+, 3.7.2+, 3.6.8, or 2.7.16+), no further action is needed to use IDLE or Tkinter. A built-in version of Tcl/Tk 8.6 will be used.

If you are using macOS 10.6 or later, the Apple-supplied Tcl/Tk 8.5 has serious bugs that can cause application crashes. If you wish to use IDLE or Tkinter, do not use the Apple-supplied Pythons. Instead, install and use a newer version of Python from python.org or a third-party distributor that supplies or links with a newer version of Tcl/Tk.

More information could refer to IDLE and tkinter with Tcl/Tk on macOS


The following is a Python 3 sample program loosely based on the documentation example but modified to avoid a global import. In Python 2 it is required to change the import statement to import Tkinter as tk with a capital T.

try:
    import tkinter as tk  # For Python3
except ImportError:
    import Tkinter as tk  # For Python2

class App(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.master = master
        self.quit = tk.Button(self, text="QUIT", command=self._destroy, fg="red")
        self.quit.pack(side="left")

        self.hello = tk.Button(self, text="Hello", command=self.say)
        self.hello.pack(side="left")

    def say(self, something="Hello World!"):
        print(something)

    def _destroy(self):
        self.master.destroy()

root = tk.Tk()
app = App(root)
app.pack(side="top", fill="both", expand=True)
app.mainloop()

Due to its power and maturity, tools such as EasyGUI (no longer maintained) have been written on top of Tkinter to make it even easier to use.

Tkinter also has powerful, built-in dialogues that can be used for easily creating native-looking, interactive dialogues. The dialogues can be accessed by import tkinter.simpledialog for Python 3 and import tkSimpleDialog for Python 2.

Related Tags :

  • - A variant on which focuses on separating widget functionality from aesthetics

References :

51180 questions
5
votes
3 answers

PySimpleGui: change font, font display, Ubuntu, ugly fonts

Out of the box it seems that the demo app examples for PySimpleGui display with an "ugly" font when using Linux (Ubuntu 20.10). As I cannot find any references how to control this in the demo examples provided, such as default_font = 'Helvetica'),…
Jaco
  • 1,564
  • 2
  • 9
  • 33
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

Get height/width of tkinter Canvas

I am searching for this for ages now. Is it so hard to get the height/width of a Canvas in tkinter? I want to do something like this: c = Tk.Canvas(self, heigth=12, width=12) c.create_oval(0, 0, self.height, self.width) So that I draw a circle with…
Vandrey
  • 531
  • 1
  • 8
  • 23
5
votes
3 answers

Update a Tkinter text widget as it's written rather than after the class is finished

I'm in a bind, since this is being written on a classified machine I am unable to copy+paste here. Being somewhat a novice, my approach is probably unorthodox. I have a GUI written in Tkinter with several buttons. Each button is linked to a class…
Ryan Gibbons
  • 51
  • 1
  • 1
  • 2
5
votes
2 answers

What is Tkinter's tkapp?

I'm using Tkinter in Python, and trying to create code to run when a text box's value is changed. All the code I find online uses a mysterious tk member of Tkinter widgets, and I can't find any documentation on it! I found it's of type tkapp, but…
bfops
  • 5,348
  • 5
  • 36
  • 48
5
votes
1 answer

tkinter: check modified

I'm a newbie python/tkinter programmer! I am displaying a text widget for the user to use as a barebones editor. Is it possible to check if the user modified it in any way, so that I know if it necessary a savefile step? thanks! alessandro
alessandro
  • 3,838
  • 8
  • 40
  • 59
5
votes
2 answers

Tkinter After Loop Only Runs to Time if Mouse Moving

I'm using after() for a Tkinter animation loop: from tkinter import Tk, Canvas from time import time root = Tk() root.configure(width=1920, height=1080) root.resizable(True, True) main = Canvas(root, width=1600, height=900) ball =…
IceBlue02
  • 71
  • 3
5
votes
1 answer

Implement text-autocompletion in python/tkinter based text editor

I would like to use an autocompletion algorithm in the main text window (not the Tkinter.entry - examples for this can be found) of this simple Tkinter text editor provided in the code box below. I thought the autocompletion algorithm of beeing…
Piotr
  • 67
  • 1
  • 4
5
votes
0 answers

Minimum System Requirements to run Python & tkinter

I'm making a POS system using Tkinter for my Computing Programming Project and for the program analysis we have to talk about the proposed solution and how we'll go about carrying out the program. For this, it's recommended to talk about system…
STRhythm
  • 113
  • 8
5
votes
2 answers

Is tkinter renamed in Python 3.9.0b3?

I just upgraded to python 3.9 (Earlier I had python 3.8.2) I was working on a project where I had to use tkinter module. Everything worked fine in Python3.8.2 But after upgrading to Python3.9 , I get this error : The error is : Traceback (most…
user13786942
5
votes
1 answer

How to save text from entry? (Python)

I'm new to python and coding in general. I'm wondering how you can save the text from answering questions to a text file. It's a diary so every time I write things down and click add, I want it to add to a text file. cue = Label(text="What…
Hassan
  • 53
  • 3
5
votes
1 answer

My image is not transparent when I am using ImageTk

I am trying to put an image into a window with ImageTk and PhotoImage. Below is the code: import tkinter as tk import random as r from PIL import ImageTk, Image window = tk.Tk() HEIGHT = window.winfo_screenwidth() WIDTH =…
10 Rep
  • 2,217
  • 7
  • 19
  • 33
5
votes
2 answers

Python - Reading Powershell script output, using subprocess, want to receive stdout line by line

Been Trying to read stdout from a Powershell script that runs for a little bit, generating output based on the number of computers it's pinging. Trying to get the data to stream into the text box, but after all I've tried, I only seem to be able to…
5
votes
2 answers

How to convert .exe file to windows setup wizard

I was creating an app through Tkinter. And after making I converted into .exe file using pyinstaller. It is good but I want to make it more professional. Like when we download any application from internet and open it it opens a setup wizard with…
Binamra
  • 164
  • 1
  • 9
5
votes
2 answers

What is the difference between .config() and .configure() in Tkinter

Im a beginner in python. Recently I finished the basics and now I'm trying to make some GUI applications. I have found many cases where we use config() and configure(). But what is the difference between config() and configure()? I mean, in what…
user14030743