Pop Up Dialog Boxes in Python GUI with tkinter - User Login Window Design

preview_player
Показать описание
This video demonstrates, how to create pop up dialog boxes such as Message Box, Error Message Box, Warning Message Box and Question Dialog Box. Also, it demonstrates how to create user login window using python gui tkinter.
Рекомендации по теме
Комментарии
Автор

#start by importing a messagebox (module) from the tkinter (module)
from tkinter import *
from tkinter import messagebox

#create a window
window = Tk()
window.title('Login')


#add textfields
l1=Label(window, text='Username:', font=(14))
l2=Label(window, text='Password:', font=(14))
l1.grid(row=0, column=0, padx=5, pady=5)
l2.grid(row=1, column=0, padx=5, pady=5)

#get username and password
username=StringVar()
password=StringVar()
t1=Entry(window, textvariable=username, font=(14))
t2=Entry(window, textvariable=password, font=(14), show='*')
t1.grid(row=0, column=1)
t2.grid(row=1, column=1)

#add login and cancel buttons
b1=Button(window, text='Login', font=(14))
b2=Button(window, text='Cancel', font=(14))

#action when login button is clicked
def login():
if username.get()=='admin' and password.get()=='admin':
status', message='You have logged in.')
else:
error', message='Username/Password is incorrect.')

b1=Button(window, command=login, text='Login', font=(14))

#action when cancel button is clicked
def cancel():
status=messagebox.askyesno(title='Question', message='Do you want to close the window?')
if status==True:
window.destroy()
else:
messagebox.showwarning(title='Warning', message='Please login again!')

b2=Button(window, command=cancel, text='Cancel', font=(14))
b1.grid(row=2, column=1, sticky=W)
b2.grid(row=2, column=1, sticky=E)

window.mainloop()

mirkovallius
Автор

Thanks for uploading this video, it helped me a lot.

ShadyShawarma
Автор

its help ful sir i doing student managemt project and there i use multiple window and i face one problem there when i use pop message user entry from is located in second window when user missed some entry field and press the confirm button the pop message work good but its move to the first window which i dont want ...how can i fix that i want the pop message show but its still stay on second window.

musharafullah
Автор

Hi! Is it safe to ask for password using input and dialog box? Will it get stored anywhere after the code is run?

Nishiansel
Автор

im witing for your reply and thanks in advance sir

musharafullah
Автор

After closing the window the next program starts running how to stop it?

Neonvarun
Автор

I got an error: TypeError: label() got an unexpected keyword argument 'text'.
What to do now?

dominik