Why widgets declared later appear first?
Question: I am using Python's `tkinter` library to create a small GUI. The code of the
app is as follows :

    
    
    import tkinter as tk
    from tkinter import ttk
    APP_TITLE = "HiDE"
    
    class Application(tk.Frame):
        """This class establishes an entity for the application"""
        #The constructor of this class
        def __init__(self, master=None):        
            tk.Frame.__init__(self,master)
            self.grid()
    
        def setupWidgets(self):
            self.message = tk.Label(self,text='Login')
            self.quitButton = tk.Button(self,text='Quit',command=self.quit)
            self.logButton = tk.Button(self,text='Login',command=self.quit)
            self.master.title(APP_TITLE)
            self.master.minsize("300","300")
            self.master.maxsize("300","300")
            self.message.grid()
            self.logButton.grid()
            self.quitButton.grid()
    
    #Setting up the application
    app = Application()
    img = tk.PhotoImage(file='icon.png')
    #getting screen parameters
    w = h = 300#max size of the window
    ws = app.master.winfo_screenwidth() #This value is the width of the screen
    hs = app.master.winfo_screenheight() #This is the height of the screen
    
    # calculate position x, y
    x = (ws/2) - (w/2)
    y = (hs/2) - (h/2)
    #This is responsible for setting the dimensions of the screen and where it is placed
    app.master.geometry('%dx%d+%d+%d' % (w, h, x, y))
    app.master.tk.call('wm', 'iconphoto', app.master._w, img)
    app.master.i_con = tk.Label(app.master, image=img)
    app.master.i_con.grid()
    app.setupWidgets()  #<-- This is the function call
    app.mainloop()
    

The `setupWidgets` function is called after the image is set up, but the
output is :

![The output](http://i.stack.imgur.com/AlKyv.png)


Answer: By the time you grid the Label with the image, you have already called grid on
the Frame in your class. This class is where the other widgets are placed in,
so it's placed above the Label with the image.

Instead of

    
    
    app.master.i_con = tk.Label(app.master, image=img)
    

try

    
    
    app.master.i_con = tk.Label(app, image=img)
    

to put the Label with the image in the Frame with the other widgets.

* * *

On a side note, calling grid without specifying a row and column doesn't
really make sense.

