Couldn't run the python application based on TKinter
Question: 
    import Tkinter as tk
    from functools import partial
    
    pad = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ["C", 0, "S"]]
    passcode = ""
    
    def append_passcode(value):
        global passcode
        if len(passcode) == 4:
            passcode = passcode[1:]
        passcode += value
    
    def clear():
        global passcode
        passcode = ""
    
    def submit():
        global passcode
        if passcode == "1234":
            msgBox.showinfo("Login Attempt", "Successful")
            passcode = ""
        else:
            msgBox.showinfo("Login Attempt", "Failed")
            passcode = ""
    
    main_window = tk.Tk()
    
    btns = []
    row_placement = 0
    for line in pad:
        col_placement = 0
        for number in line:
            btn_command = partial(append_passcode, str(number))
            btn = tk.Button(main_window, text=str(number), width=10, command=btn_command)
            btns.append(btn)
            btn.grid(row=row_placement, column=col_placement)
            col_placement += 1
        row_placement += 1
    
    #Setting C to clear the passcode function
    btns[-3].config(command=clear)
    
    #Setting S to submit passcode
    btns[-1].config(command=submit)
    

I'm writing an numpad application where user must enter the correct 4 digit
code to access application. when the test code runs, the GUI does not appear.
What needs to be done to get this code to function?


Answer: Here's what you've done wrong:

  * Misspelled tkinter
  * Not included 
    
        main_window.mainloop()
    

Try this code

    
    
    import tkinter as tk
    from functools import partial
    
    pad = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ["C", 0, "S"]]
    passcode = ""
    
    def append_passcode(value):
        global passcode
        if len(passcode) == 4:
            passcode = passcode[1:]
        passcode += value
    
    def clear():
        global passcode
        passcode = ""
    
    def submit():
        global passcode
        if passcode == "1234":
            msgBox.showinfo("Login Attempt", "Successful")
            passcode = ""
        else:
            msgBox.showinfo("Login Attempt", "Failed")
            passcode = ""
    
    main_window = tk.Tk()
    
    btns = []
    row_placement = 0
    for line in pad:
        col_placement = 0
        for number in line:
            btn_command = partial(append_passcode, str(number))
            btn = tk.Button(main_window, text=str(number), width=10, command=btn_command)
            btns.append(btn)
            btn.grid(row=row_placement, column=col_placement)
            col_placement += 1
        row_placement += 1
    
    #Setting C to clear the passcode function
    btns[-3].config(command=clear)
    
    #Setting S to submit passcode
    btns[-1].config(command=submit)
    
    main_window.mainloop()
    

Now your window should appear.

Hope this helps and feel free to comment any questions.

