PyTut: Tkinter #1

R

Rick Johnson

PyTut: Tkinter #1
Graciously donated by the benevolent professor Richard Johnson

The first step to creating a Tkinter GUI is to create a blank window.
Tkinter has two classes that represent a GUI window: Toplevel and Tk.
Both the classes are basically the same, but since a GUI can have an
unlimited number of Toplevel windows, the very first window should
ALWAYS be an instance of Tk! Let's write some code.

## START CODE ##
import Tkinter as tk

root = tk.Tk()
root.mainloop()
## END CODE ##

You can probably guess what the first line does; it creates your
parent Toplevel window as an instance of Tk! The second line
"root.mainloop()" enters the event loop. Don't worry about the details
of "mainloop" at this time, just remeber that all Tkinter GUIs start
with an instance of Tk and end with a call to mainloop.

Here is the same code in a strict OOP form (For something this simple
you need not use strict OOP but eventually you will need to harness
the power of OOP!)

## START CODE ##
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)

app = App()
app.mainloop()
## END CODE ##

That's all folks! Keep your eyes peeled for the next glorious
installment of "PyTut: Tkinter"!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top