1

I am trying to create a window with Tkinter but no window is being created and I am not receiving any error codes?

from tkinter import *
def login_window():
 window=Tk()
 window.title("Login")
 info_lbl = Label(window)
 info_lbl.grid(row=0, column=1)
 username_lbl = Label(window, text='Username')
 username_lbl.grid(row=1, column=1)
 username_entry = Entry(window, width=10)
 username_entry.grid(row=1, column=2)
 password_lbl = Label(window, text='Password')
 password_lbl.grid(row=2, column=1)
 password_entry = Entry(window, width=10, )
 password_entry.grid(row=2, column=2)
 ok_button = Button(window, text='Login', command = menu_window)
 ok_button.grid(row=3,column = 2,sticky =W)

Any help would be great!

T.E
  • 31
  • 4

2 Answers2

1

It looks like you never entered the main Tkinter loop. To display that window, you could add this to the bottom of the function:

window.mainloop()

Take a look at this question and the accepted answer for a bit more information on the Tkinter main loop.

Community
  • 1
  • 1
bytesized
  • 1,502
  • 13
  • 22
1

Well I think u should add mainloop() inside your function as well as call your login_window something like this-

from Tkinter import *
def login_window():
     window=Tk()
     window.title("Login")
     mainloop()
login_window()
saqib1707
  • 38
  • 8