Coding (basic window):
Most Tkinter coding will have the following:
from tkinter import *
root = Tk()
root.title("Title")
root.geometry("800x500+10+100")
root.configure(bg='bisque')
from tkinter import * – imports every exposed object in Tkinter into your current namespace.
root = Tk() – Tk() is an application window. We have named the window root. The root
window is a main application window in our programs. It has a title bar and borders. These are
provided by the window manager. It must be created before any other widgets. It doesn’t have to
be named root.
root.title("Title") – this adds a name to the title bar.
root.geometry("800x500+10+100") – The geometry method sets a size for the window and
positions it on the screen. The first two parameters are the width and height of the window.
The last two parameters are x and y screen coordinates.
root.configure(bg='bisque') – configuration settings.
bd or borderwidth – places a border on the window. Widgets will set inside this border.
(ex: bd=10) Default is 2 pixels.
bg or background – background color. See Color Chart from Color Chart.py.
(ex: bg=”red”)
cursor – Here is the list of interesting ones −"arrow", "circle", "clock", "cross", "dotbox",
"exchange", "fleur", "heart", "man", "mouse", "pirate", "plus", "shuttle", "sizing", "spider",
"spraycan", "star", "target", "tcross", "trek", "watch"
height and width – sets the height or width of the window. If root.geometry is already set this
will not override.
root.mainloop() – At the end we enter the mainloop. The event handling starts from this point.
The mainloop receives events from the window system and dispatches them to the application
widgets. It is terminated when we click on the close button of the titlebar or call the quit() method.
No comments:
Post a Comment