Is it necessary to call Tk() when writing a GUI app with Tkinter?

Rick Johnson rantingrickjohnson at gmail.com
Fri Mar 2 03:53:12 CET 2012


On Feb 29, 11:40 pm, John Salerno <johnj... at gmail.com> wrote:
> The faulty code is not my own, which is part of the reason I asked
> the question. The book I'm reading (The Quick Python Book) does not
> use it, but I saw in the Python docs that it is there, under
> "tkinter" in the Global Module Docs, "24.1.2.2. A Simple Hello World
> Program":

Book authors and Doc authors are not always the most well informed; as
we have witnessed by this very thread!

> from tkinter import *

don't do that!

> class Application(Frame):
>     def say_hi(self):
>         print("hi there, everyone!")
>
>     def createWidgets(self):
>         self.QUIT = Button(self)
>         self.QUIT["text"] = "QUIT"
>         self.QUIT["fg"] = "red"
>         self.QUIT["command"] = self.quit
>
>         self.QUIT.pack({"side": "left"})

don't do that either! Widgets take optional keyword arguments now so
stop passing in dictionaries.

 self.quit.pack(side=tk.LEFT)

Obviously these tutorials are more like: "What NOT to do when coding
Tkinter GUIs!" No wonder everyone hates Tkinter.  :-)



More information about the Python-list mailing list