Difference between revisions of "Tkinter"

Jump to navigation Jump to search
Line 2: Line 2:
<div style="float: right; margin-left: 12px">__TOC__</div>
<div style="float: right; margin-left: 12px">__TOC__</div>


'''Tkinter''' is a [[Python (programming language)|Python]] [[Language binding|binding]] to the [[Tk (software)|Tk]] [[Graphical user interface|GUI]] toolkit. It is the standard Python interface to the Tk GUI toolkit,<ref>{{cite web | url=https://docs.python.org/library/tkinter.html | title=Tkinter — Python interface to Tcl/Tk — Python v2.6.1 documentation | accessdate=2009-03-12}}</ref> and is Python's [[de facto standard|''de facto'' standard]] GUI.<ref>{{cite web | url=https://wiki.python.org/moin/TkInter | title= Tkinter - Pythoninfo Wiki}}</ref> Tkinter is included with standard [[Linux]], [[Microsoft Windows]] and [[Mac OS X]] installs of Python.
'''Tkinter''' is a [[Python (programming language)|Python]] [[Language binding|binding]] to the [[Tk (software)|Tk]] [[Graphical user interface|GUI]] toolkit. It is the standard [[Python]] interface to the Tk GUI toolkit,<ref>{{cite web | url=https://docs.python.org/library/tkinter.html | title=Tkinter — Python interface to Tcl/Tk — Python v2.6.1 documentation | accessdate=2009-03-12}}</ref> and is Python's [[de facto standard|''de facto'' standard]] GUI.<ref>{{cite web | url=https://wiki.python.org/moin/TkInter | title= Tkinter - Pythoninfo Wiki}}</ref> Tkinter is included with standard [[Linux]], [[Microsoft Windows]] and [[Mac OS X]] installs of Python.


The name ''Tkinter'' comes from ''Tk interface''. Tkinter was written by Fredrik Lundh.<ref>{{citation | url=http://infohost.nmt.edu/tcc/help/pubs/tkinter/ | title=Tkinter reference: a GUI for Python | first=John W. | last=Shipman | publisher=New Mexico Tech Computer Center | date=2010-12-12 | accessdate=2012-01-11}}</ref>
The name ''Tkinter'' comes from ''Tk interface''. Tkinter was written by Fredrik Lundh.<ref>{{citation | url=http://infohost.nmt.edu/tcc/help/pubs/tkinter/ | title=Tkinter reference: a GUI for Python | first=John W. | last=Shipman | publisher=New Mexico Tech Computer Center | date=2010-12-12 | accessdate=2012-01-11}}</ref>


Tkinter is [[free software]] released under a [[Python license]].<ref>{{cite web |url=http://tkinter.unpythonic.net/wiki/Tkinter |title=Archived copy |accessdate=2013-11-13 |url-status=dead |archiveurl=https://web.archive.org/web/20131113222939/http://tkinter.unpythonic.net/wiki/Tkinter |archivedate=2013-11-13 }}</ref>
Tkinter is [[free software]] released under a [[Python license]].<ref>{{cite web |url=http://tkinter.unpythonic.net/wiki/Tkinter |title=Archived copy |accessdate=2013-11-13 |url-status=dead |archiveurl=https://web.archive.org/web/20131113222939/http://tkinter.unpythonic.net/wiki/Tkinter |archivedate=2013-11-13 }}</ref>
The [[source code]]s of this [[article]] were tested with [[Python]] 3.7.5 on [[Ubuntu]] 9.10.
from tkinter import *
or
import tkinter as tk
Input the above line into your [[Python]] 3 [[source code]].
Input the below [[command]] in your [[terminal]].
sudo apt install python3-tk
Use [[VSCodium]] or any [[ource-code editor]] to edit your [[source code]]s.
You can execute your program like the below command.
python3 cal.py
== Elements arrangement by using "pack" and "grid" ==
root=Tk()
To show a blank window
root.mainloop()
"(Tk object).mainloop()" -> make a window to get an entry
from tkinter import *
root=Tk()
root.mainloop()
complete [[source code]]
pussy = widget_name(new_Tk_object, ... )
pussy.pack()
make a new widget
root = Tk()
sister_pussy = Label(root, text = "sis pussy")
sister_pussy.pack()
complete source code
Displacement of a widget
1. place
2. pack
3. grid
"grid" is similar to a table.
from tkinter import *
root = Tk()
sister_pussy = Label(root, text = "sis pussy")
sister_pussy.pack()
root.mainloop()
complete source code
=== 1 label, 1 text box, and 2 buttons ===
A window made by "grid".
from tkinter import *
root = Tk()
title = Label(root,text="Input")
txtbox = Entry(root, width = 15)
btn_1= Button(root, text = "Submit", width=10)
btn_2 = Button(root, text= "Cancel", width=10)
title.grid(row=0, column=0)
txtbox.grid(row=0, column=1)
btn_1.grid(row=1,column=1)
btn_2.grid(row=2, column=1)
root.mainloop()
"Entry" is for inputting texts.
btn_1.grid(row=1,column=1)
btn_2.grid(row=1,column=1)
If two elements have been placed at the same place, the last one replaces the prior one. In this case, the "button 2" will replace the "button 1".


== GUI calculator ==
== GUI calculator ==
Line 248: Line 346:
** [[Programming language]], an artificial language designed to communicate instructions to a machine
** [[Programming language]], an artificial language designed to communicate instructions to a machine
* [[Programmer]], a person who writes software
* [[Programmer]], a person who writes software
* [[I2P]]


== References ==
== References ==