How to Make a Window in Python
- 1). Setup the program up for Tkinter. In the text editor, enter the following code:
#!/usr/bin/python
from Tkinter import *
root = Tk()
This sample code imports the Tkinter libraries into the working program. This means that the programmer can access the Tkinter libraries programatically through Tkinter objects. Then, the variable "root" is instantiated as a Tkinter object . This is a root widget, and there should only be one per program. - 2). Add the following code in the text editor:
root.title("New Window")
root.geometry("200x200")
root.mainloop()
"root.title" sets the title of the window (located in the title bar) to "New Window." "Root.geometry" sets the dimensions of the window to 200 pixels by 200 pixels. The "root.mainloop" method is the main method: the window will not appear until the main loop executes. - 3). Save the file and execute the program:
python filename.py
Where "filename" is the name of the save file. The window should appear, as a 200x200 square with the proper title.