This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
1
Can someone help me with this tkinter error: File “main.py”, line 69, in login image = PIL.Image.open(movie_image) File “/usr/local/lib/python3.6/dist-packages/PIL/Image.py”, line 2652, in open fp = builtins.open(filename, “rb”) FileNotFoundError: [Errno 2] No such file or directory: ‘a.jpg’
Post Body
import tkinter as tk
from tkinter import messagebox
from PIL import Image, ImageTk
from db import UserDatabase
import random
from tkinter import simpledialog
from tkinter import ttk
from tkinter import *
import PIL.Image
movies={
"Thor Love and Thunder":"a.jpg",
"Spiderman 2":"b.jpg",
"Iron man 3":"c.jpg"}
class Login_app(tk.Tk):
def __init__(self):
super().__init__()
#set up of the main window
self.title("Login")
self.geometry("300x200")
#Creation of username and password entry fields
self.username_label=tk.Label(self,text="username")
self.username_label.pack()
self.username_entry=tk.Entry(self)
self.username_entry.pack()
self.password_label = tk.Label(self, text="Password")
self.password_label.pack()
self.password_entry = tk.Entry(self, show="*")
self.password_entry.pack()
# Create the login and create account buttons
self.login_button = tk.Button(self, text="Login", command=self.login)
self.login_button.pack()
self.create_button = tk.Button(self, text="Create Account", command=self.create_account)
self.create_button.pack()
# Create a database instance
self.db = UserDatabase('users.db')
def login(self):
# Get the username and password from the entry fields
username = self.username_entry.get()
password = self.password_entry.get()
self.movie_listbox = tk.Listbox(self)
self.movie_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
user = self.db.get_user(username)
# Check if the username and password match a user in the database
if user and user[2] == password:
# Show a message box indicating successful login
messagebox.showinfo("Success", "Login successful!")
# Create a new window for the dashboard
dashboard = tk.Toplevel(self)
dashboard.title("Dashboard")
# Add a label and buttons to the dashboard
label = tk.Label(dashboard, text="Choose a movie to book:")
label.pack()
for movie_name, movie_image in movies.items():
# Load the movie image
image = PIL.Image.open(movie_image)
# Resize the image to fit the button
image = image.resize((100, 100))
# Convert the image to a format that Tkinter can display
photo = ImageTk.PhotoImage(image)
# Create a button for the movie
movie_button = tk.Button(dashboard, image=photo, command=lambda name=movie_name: self.book_movie(name))
movie_button.image = photo # Store a reference to the photo to prevent rubbish collection
movie_button.pack()
# Hide the login window
self.withdraw()
else:
# Show a message box indicating login failure
messagebox.showerror("Error", "Invalid username or password.")
def book_movie(self, movie_name):
# Show a message box asking the user to confirm the booking
result = messagebox.askquestion("Confirm Booking", f"Are you sure you want to book the movie {movie_name}?")
if result == 'yes':
# Book the movie in the database
self.db.book_movie(self.username_entry.get(), movie_name)
# Ask the user for the number of tickets to book
num_tickets = simpledialog.askinteger("Number of Tickets", "How many tickets would you like to book? (maximum 2)", minvalue=1, maxvalue=2)
if num_tickets:
# Generate a list of available seats
available_seats = self.db.get_available_seats(movie_name)
# Shuffle the list to get a random seat
random.shuffle(available_seats)
# Select the first two seats (if available)
selected_seats = available_seats[:num_tickets]
# Update the database with the selected seats
for seat in selected_seats:
self.db.book_movie(self.username_entry.get(), movie_name)
# Show a success message
messagebox.showinfo("Success", "Tickets booked successfully! Find the ticket as text file in this folder")
# Create a text file for the ticket
with open(f"{movie_name}_ticket.txt", 'w') as ticket_file:
ticket_file.write("Movie: " movie_name "\n")
ticket_file.write("Seats: " ", ".join(str(seat) for seat in selected_seats) "\n")
ticket_file.write("Enjoy the show!")
else:
# Show a message indicating the booking was cancelled
messagebox.showinfo("Cancelled", "Booking cancelled.")
else:
# Show a message indicating the booking was cancelled
messagebox.showinfo("Cancelled", "Booking cancelled.")
def create_account(self):
# Get the username and password from the entry fields
username = self.username_entry.get()
password = self.password_entry.get()
if password=='':
messagebox.showerror("Error", "input password!")
check= self.db.get_user(username)
if check:
messagebox.showerror("Error", "User already there!")
else:
self.db.add_user(username, password)
run the tkinter ap
if name == 'main':
app = Login_app()
app.mainloop()
Author
Account Strength
80%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
43
Link Karma
42
Comment Karma
1
Profile updated: 2 days ago
Posts updated: 1 year ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...