Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Description  



1.1  Some definitions  



1.1.1  Window  





1.1.2  Top-level window  





1.1.3  Widget  





1.1.4  Frame  





1.1.5  Child and parent  









2 A minimal application  



2.1  Process  





2.2  Simple application  







3 See also  





4 References  





5 External links  














Tkinter






العربية

Català
Čeština
Deutsch
Eesti
Español
Esperanto
فارسی
Français

Bahasa Indonesia
Italiano
עברית

Polski
Português
Русский
Türkçe
Українська

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikimedia Commons
Wikibooks
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


Tkinter
LicensePython license
Websitewiki.python.org/moin/TkInter Edit this on Wikidata

Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit,[1] and is Python's de facto standard GUI.[2] Tkinter is included with standard Linux, Microsoft Windows and macOS installs of Python.

The name Tkinter comes from Tk interface. Tkinter was written by Steen Lumholt and Guido van Rossum,[3] then later revised by Fredrik Lundh.[4]

Tkinter is free software released under a Python license.[5]

Description

[edit]

As with most other modern Tk bindings, Tkinter is implemented as a Python wrapper around a complete Tcl interpreter embedded in the Python interpreter. Tkinter calls are translated into Tcl commands, which are fed to this embedded interpreter, thus making it possible to mix Python and Tcl in a single application.

There are several popular GUI library alternatives available, such as Kivy, Pygame, Pyglet, PyGObject, PyQt, PySide, and wxPython.

Some definitions

[edit] [edit]

This term has different meanings in different contexts, but in general it refers to a rectangular area somewhere on the user's display screen.

Top-level window

[edit]

A window which acts as a child of the primary window. It will be decorated with the standard frame and controls for the desktop manager. It can be moved around the desktop and can usually be resized.

Widget

[edit]

The generic term for any of the building blocks that make up an application in a graphical user interface.

Frame

[edit]

In Tkinter, the Frame widget is the basic unit of organization for complex layouts. A frame is a rectangular area that can contain other widgets.

Child and parent

[edit]

When any widget is created, a parent–child relationship is created. For example, if you place a text label inside a frame, the frame is the parent of the label.

A minimal application

[edit]

Here is a minimal Python 3 Tkinter application with one widget:[9]

#!/usr/bin/env python3
from tkinter import *
root = Tk()        # Create the root (base) window 
w = Label(root, text="Hello, world!")  # Create a label with words
w.pack()         # Put the label into the window
root.mainloop()       # Start the event loop

For Python 2, the only difference is the word "tkinter" in the import command will be capitalized to "Tkinter".[10]

Process

[edit]

There are four stages to creating a widget[11]

Create
create it within a frame
Configure
change the widgets attributes.
Pack
pack it into position so it becomes visible. Developers also have the option to use .grid() (row=int, column=int to define rows and columns to position the widget, defaults to 0) and .place() (relx=int or decimal, rely=int or decimal, define coordinates in the frame, or window).
Bind
bind it to a function or event.

These are often compressed, and the order can vary.

Simple application

[edit]

Using the object-oriented paradigm in Python, a simple program would be (requires Tcl version 8.6, which is not used by Python on MacOS by default):

#!/usr/bin/env python3
import tkinter as tk


class Application(tk.Frame):

    def __init__(self, root=None):
        tk.Frame.__init__(self, root)
        self.grid()
        self.createWidgets()

    def createWidgets(self):
        self.medialLabel = tk.Label(self, text='Hello World')
        self.medialLabel.config(bg="#00ffff")
        self.medialLabel.grid()
        self.quitButton = tk.Button(self, text='Quit', command=self.quit)
        self.quitButton.grid()


app = Application()
app.root.title('Sample application')
app.mainloop()

See also

[edit]

References

[edit]
  1. ^ "Tkinter — Python interface to Tcl/Tk — Python v2.6.1 documentation". Retrieved 2009-03-12.
  • ^ "Tkinter - Pythoninfo Wiki".
  • ^ tkinter—Python interface to Tcl/Tk—Python 3.9.10 Documentation
  • ^ Shipman, John W. (2010-12-12), Tkinter reference: a GUI for Python, New Mexico Tech Computer Center, retrieved 2012-01-11
  • ^ "Tkinter - Tkinter Wiki". Archived from the original on 2013-11-13. Retrieved 2013-11-13.
  • ^ "Python issue #2983, "Ttk support for Tkinter"".
  • ^ "Python subversion revision 69051, which resolves issue #2983 by adding the ttk module".
  • ^ "Tkinter ttk widgets - Python Tutorial". CodersLegacy. Retrieved 2022-01-13.
  • ^ "Tkinter 8.5 reference: a GUI for Python".
  • ^ Fleck, Dan. "Tkinter – GUIs in Python" (PDF). CS112. George Mason University. Retrieved 18 August 2018.
  • ^ Klein, Bernd. "GUI Programming with Python: Events and Binds". www.python-course.eu. Retrieved 18 August 2018.
  • ^ "PEP 397 — Python launcher for Windows — Python.org". Retrieved 2017-06-07.
  • [edit]
    Retrieved from "https://en.wikipedia.org/w/index.php?title=Tkinter&oldid=1230521509"

    Categories: 
    Python (programming language) libraries
    Tk (software)
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
     



    This page was last edited on 23 June 2024, at 06:15 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki