Difference between revisions of "Creating a Window - Tkinter"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "Creating the basic window for your application is much simpler with Python and Tkinter than in most other languages. We start by creating an instance of the Tk() class from th...")
 
m (000030906 moved page Creating a Window - Python to Creating a Window - Tkinter: changing the way i name these pages)
 
(No difference)

Latest revision as of 10:48, 14 September 2018

Creating the basic window for your application is much simpler with Python and Tkinter than in most other languages. We start by creating an instance of the Tk() class from the tkinter library. This creates a 'Top Level' widget, which will act as the main window for our application. Here's an example of the general setup for the main window:

from tkinter import *

root = Tk()
root.title("Window's Title")
root.geometry("400x300")

root.mainloop()

In this code, we import the Tkinter library, we create an instance of the Tk() class (and call it root), we then set the title of the window, as well as set the dimensions of the window, and then finally we call the mainloop() method to open the window and start the loop of events.

Note: The size of the window (geometry) is measured in pixels.