This Tkinter program displays a single label. Clicking the window's "close" decoration makes the program exit:

Python 2

import Tkinter
l = Tkinter.Label(text = "See me?")
l.pack()
l.mainloop()

Python 3

import tkinter
l = tkinter.Label(text = "See me?")
l.pack()
l.mainloop()

The last line might not even be necessary if you're using an interactive shell.


Technically, the simplest possible Tkinter program would be one without the label; instead, just:

Python 2

import Tkinter
m = Tkinter.Tk()
m.mainloop()

Python 3

import tkinter
m = tkinter.Tk()
m.mainloop()

This will just display an empty gray (or other color, depending on your system settings) window with a generic title bar!


Return to Tkinter_for_beginners.

tkinter: the_simplest_possible_Tkinter_program (last edited 2014-03-16 21:30:19 by sam)