The program should consist when after login successfully the image, name, nickname, favorite food and aritst will display after. When I run the code, the information wont display. The image will only display entirely. The code should consist of an image, name, favorite artist, favorite food, and favorite artist. ("random.jpg just appload a random pic to test) Code: from tkinter import * from tkinter import messagebox from PIL import ImageTk, Image # Create the main window root = Tk() root.title("Login") # Create the username label and entry field username_label = Label(root, text="Username:") username_label.grid(row=0, column=0) username_entry = Entry(root) username_entry.grid(row=0, column=1) # Create the password label and entry field password_label = Label(root, text="Password:") password_label.grid(row=1, column=0) password_entry = Entry(root, show="*") password_entry.grid(row=1, column=1) # Create the login button def login(): if username_entry.get() == "admin" and password_entry.get() == "password": messagebox.showinfo("Login", "Login Successful!") root.destroy() # Create the new window new_window = Tk() new_window.title("Welcome") # Load and display the image image = Image.open("random.jpg") photo = ImageTk.PhotoImage(image) image_label = Label(new_window, image=photo) image_label.pack() # Create the user information labels name_label = Label(new_window, text="Name: Doe") name_label.pack() address_label = Label(new_window, text="Address: 123 Main Street") address_label.pack() food_label = Label(new_window, text="Favorite Food: Pizza") food_label.pack() artist_label = Label(new_window, text="Favorite Artist: Beyonce") artist_label.pack() new_window.mainloop() else: messagebox.showerror("Login", "Invalid username or password") login_button = Button(root, text="Login", command=login) login_button.grid(row=2, column=1) root.mainloop()
The program should consist when after login successfully the image, name, nickname, favorite food and aritst will display after. When I run the code, the information wont display. The image will only display entirely. The code should consist of an image, name, favorite artist, favorite food, and favorite artist. ("random.jpg just appload a random pic to test)
Code:
from tkinter import *
from tkinter import messagebox
from PIL import ImageTk, Image
# Create the main window
root = Tk()
root.title("Login")
# Create the username label and entry field
username_label = Label(root, text="Username:")
username_label.grid(row=0, column=0)
username_entry = Entry(root)
username_entry.grid(row=0, column=1)
# Create the password label and entry field
password_label = Label(root, text="Password:")
password_label.grid(row=1, column=0)
password_entry = Entry(root, show="*")
password_entry.grid(row=1, column=1)
# Create the login button
def login():
if username_entry.get() == "admin" and password_entry.get() == "password":
messagebox.showinfo("Login", "Login Successful!")
root.destroy()
# Create the new window
new_window = Tk()
new_window.title("Welcome")
# Load and display the image
image = Image.open("random.jpg")
photo = ImageTk.PhotoImage(image)
image_label = Label(new_window, image=photo)
image_label.pack()
# Create the user information labels
name_label = Label(new_window, text="Name: Doe")
name_label.pack()
address_label = Label(new_window, text="Address: 123 Main Street")
address_label.pack()
food_label = Label(new_window, text="Favorite Food: Pizza")
food_label.pack()
artist_label = Label(new_window, text="Favorite Artist: Beyonce")
artist_label.pack()
new_window.mainloop()
else:
messagebox.showerror("Login", "Invalid username or password")
login_button = Button(root, text="Login", command=login)
login_button.grid(row=2, column=1)
root.mainloop()
Step by step
Solved in 3 steps with 3 images