he following methods are provided by all widgets (including the root window).
The root window and other Toplevel windows provide additional methods. See the Window Methods section for more information.
Patterns
Configuration
w.config(option=value)
value = w.cget("option")
k = w.keys()
Event processing
mainloop()
w.mainloop()
w.quit()
w.wait_variable(var)
w.wait_visibility(window)
w.wait_window(window)
w.update()
w.update_idletasks()
Event callbacks
w.bind(event, callback)
w.unbind(event)
w.bind_class(event, callback)
w.bindtags()
w.bindtags(tags)
Alarm handlers and other non-event callbacks
id = w.after(time, callback)
id = w.after_idle(callback)
w.after_cancel(id)
Window management
w.lift()
w.lower()
Window-related information
w.winfo_width(), w.winfo_height()
w.winfo_reqwidth(), w.winfo_reqheight()
w.winfo_id()
The option database
w.option_add(pattern, value)
w.option_get(name, class)
Grid Geometry Manager
The grid manager is the most flexible of the geometry managers in Tkinter. The Grid geometry manager puts the widgets in a 2-dimensional table.
Example:
# import tkinter module
from tkinter import * from tkinter.ttk import *
# creating main tkinter window/toplevel
master = Tk()
# this wil create a label widget
l1 = Label(master, text = "First:")
l2 = Label(master, text = "Second:")
# grid method to arrange labels in respective
# rows and columns as specified
l1.grid(row = 0, column = 0, sticky = W, pady = 2)
l2.grid(row = 1, column = 0, sticky = W, pady = 2)
# entry widgets, used to take entry from user
e1 = Entry(master)
e2 = Entry(master)
# this will arrange entry widgets
e1.grid(row = 0, column = 1, pady = 2)
e2.grid(row = 1, column = 1, pady = 2)
# infinite loop which can be terminated by keyboard
# or mouse interrupt
mainloop()
Output: