Help Pa help po python code pa Correct sa error na iirita na ako error pati si ChatGPT naguguluhan

XsanX

𝑩𝑶𝑹𝑵 𝑻𝑶 𝑩𝑬 𝑵𝑶𝑻𝑯𝑰𝑵𝑮
Elite
Joined
May 25, 2020
Posts
1,552
Solutions
1
Reaction
4,127
Points
894
Ito po yung error 👇

/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py:179: UserWarning: CTkLabel Warning: Given image is not CTkImage but <class 'tkinter.PhotoImage'>. Image can not be scaled on HighDPI displays, use CTkImage instead.


warnings.warn(f"{type(self).name} Warning: Given image is not CTkImage but {type(image)}. Image can not be scaled on HighDPI displays, use CTkImage instead.\n")
Exception in Tkinter callback
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/tkinter/init.py", line 1892, in call
return self.func(*args)
File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/customtkinter/windows/widgets/ctk_button.py", line 554, in _clicked
self._command()
File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 17, in update_info
new_birthday = birthday_entry.get().strip()
NameError: name 'birthday_entry' is not defined


Ito po yung code 👇

Python:
import tkinter
from tkinter import messagebox
from PIL import Image, ImageTk
from tkinter import PhotoImage
import customtkinter as ctk
import json


reg_win = None  # Declare reg_win as a global variable

def show_user_info_window(username, password, user_info):
    global update_info_win, name_entry, age_entry, birthday_entry, email_entry

    def update_info():
        new_name = name_entry.get().strip()
        new_age = age_entry.get().strip()
        new_birthday = birthday_entry.get().strip()
        new_email = email_entry.get().strip()

        if not new_name or not new_age or not new_birthday or not new_email:
            messagebox.showerror("Error", "Please fill all fields.")
            return

        user_info['Name'] = new_name
        user_info['Age'] = new_age
        user_info['Birthday'] = new_birthday
        user_info['Email'] = new_email

        # Update the displayed information
        update_display()

        messagebox.showinfo("Success", "Information updated successfully.")
        update_info_win.destroy()

    def update_display():
        updated_info_text = f"Name: {user_info.get('Name', '')}\nAge: {user_info.get('Age', '')}\nBirthday: {user_info.get('Birthday', '')}\nEmail: {user_info.get('Email', '')}"
        info_display.config(state=tkinter.NORMAL)  # Enable editing
        info_display.delete(1.0, tkinter.END)
        info_display.insert(tkinter.END, updated_info_text)
        info_display.config(state=tkinter.DISABLED)  # Make it read-only

    user_info_win = tkinter.Toplevel(app)
    user_info_win.geometry("700x800")
    user_info_win.title('User Information - GUI')

    info_label = ctk.CTkLabel(master=user_info_win, text=f"User Information for {username}", font=('Century Gothic', 16))
    info_label.pack(pady=10)

    info_text = f"Name: {user_info.get('Name', '')}\nAge: {user_info.get('Age', '')}\nBirthday: {user_info.get('Birthday', '')}\nEmail: {user_info.get('Email', '')}"

    info_display = tkinter.Text(master=user_info_win, font=('Century Gothic', 12), height=10, width=40)
    info_display.insert(tkinter.END, info_text)
    info_display.config(state=tkinter.DISABLED)  # Make it read-only
    info_display.pack(pady=10)

    edit_button = ctk.CTkButton(master=user_info_win, text="Edit Information", width=20, command=lambda: edit_info())
    edit_button.pack(pady=10)

    def edit_info():
        global update_info_win, name_entry, age_entry, birthday_entry, email_entry
        update_info_win = tkinter.Toplevel(app)
        update_info_win.geometry("700x800")
        update_info_win.title('Edit Information - GUI')

        name_label = ctk.CTkLabel(master=update_info_win, text="Name:", font=('Century Gothic', 12))
        name_label.pack(pady=5)
        name_entry = ctk.CTkEntry(master=update_info_win, width=250)
        name_entry.insert(0, user_info.get('Name', ''))
        name_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

        age_label = ctk.CTkLabel(master=update_info_win, text="Age:", font=('Century Gothic', 12))
        age_label.pack(pady=5)
        age_entry = ctk.CTkEntry(master=update_info_win, width=250)
        age_entry.insert(0, user_info.get('Age', ''))
        age_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

        # Similar modifications for birthday and email...

        update_button = ctk.CTkButton(master=update_info_win, text="Update", width=20, command=update_info)
        update_button.pack(pady=10)


    
def open_registration_window():
    global reg_win, entry3, entry4, entry5, entry6, entry7, entry8

    print("Open Registration Window")
    reg_win = tkinter.Toplevel(app)
    reg_win.geometry("700x800")
    reg_win.title('Registration - GUI')

    entry3 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Username')
    entry3.place(x=50, y=135)

    entry4 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Password', show="*")
    entry4.place(x=50, y=180)

    entry5 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Full Name')
    entry5.place(x=50, y=245)

    entry6 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Age')
    entry6.place(x=50, y=290)

    entry7 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Birthday (MM-DD-YYYY)')
    entry7.place(x=50, y=345)

    entry8 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Email')
    entry8.place(x=50, y=400)

    entry3 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Username')
    entry3.place(x=50, y=135)

    entry4 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Password', show="*")
    entry4.place(x=50, y=180)

    entry5 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Full Name')
    entry5.place(x=50, y=245)

    entry6 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Age')
    entry6.place(x=50, y=290)

    entry7 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Birthday (MM-DD-YYYY)')
    entry7.place(x=50, y=345)

    entry8 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Email')
    entry8.place(x=50, y=400)

    # Button to trigger the registration process
    register_button = ctk.CTkButton(master=reg_win, width=220, text="Register", corner_radius=6, command=lambda: register(entry3, entry4, entry5, entry6, entry7, entry8))
    register_button.place(x=50, y=450)

def register(entry_username, entry_password, entry_name, entry_age, entry_birthday, entry_email):
    global reg_win  # Reference the global variable
    username = entry_username.get().strip()
    password = entry_password.get().strip()
    name = entry_name.get().strip()
    age = entry_age.get().strip()
    birthday = entry_birthday.get().strip()
    email = entry_email.get().strip()
    
    user_info = {
        'Name': name,
        'Age': age,
        'Birthday': birthday,
        'Email': email
    }
    
    if not username or not password or not name or not age or not birthday or not email:
        messagebox.showerror("Error", "Please fill all fields.")
        return
    
    credentials = load_credentials()
    credentials[username] = {"password": password, 'user_info': user_info}
    
    with open('credentials.json', 'w') as f:
        json.dump(credentials, f)
    
    messagebox.showinfo("Success", "Registration successful.")
    reg_win.destroy()

        
def load_credentials():
    try:
        with open('credentials.json', 'r') as f:
            return json.load(f)
    except FileNotFoundError:
        return {}
        
def update_credentials(username, password, user_info=None):
    credentials = load_credentials()
    credentials[username] = {'password': password, 'user_info': user_info}
    
    with open('credentials.json', 'w') as f:
        json.dump(credentials, f)

def login():
    username = entry1.get().strip()
    password = entry2.get().strip()
    
    credentials = load_credentials()
    
    if username in credentials and credentials[username].get('password', '').strip() == password:
        user_info = credentials[username].get('user_info', {})
        show_user_info_window(username, password, user_info)
        # open_main_menu(username)
    else:
        messagebox.showerror("Error", "Invalid username or password.")

app = ctk.CTk()
app.geometry("700x800")
app.title('Login - GUI')

img1 = PhotoImage(file="vilo.gif")
l1 = ctk.CTkLabel(master=app, image=img1)
l1.pack()

frame = ctk.CTkFrame(master=l1, width=320, height=360, corner_radius=15)
frame.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)

l2 = ctk.CTkLabel(master=frame, text="Log in", font=('Century Gothic', 20))
l2.place(x=120, y=45)

entry1 = ctk.CTkEntry(master=frame, width=220, placeholder_text='Username')
entry1.place(x=50, y=110)


entry2 = ctk.CTkEntry(master=frame, width=220, placeholder_text='Password', show="*")
entry2.place(x=50, y=165)


button1 = ctk.CTkButton(master=frame, width=220, text="Log in", corner_radius=6, command=login)
button1.place(x=50, y=210)

button2 = ctk.CTkButton(master=frame, width=220, text="Sign up", corner_radius=6, command=open_registration_window)
button2.place(x=50, y=260)

app.mainloop()
 
Ang error na iyong binigay ay may dalawang bahagi. Una, may UserWarning na nagpapahiwatig na ang larawan na ibinigay ay hindi isang CTkImage kundi isang tkinter.PhotoImage. Ibig sabihin, ang larawan ay hindi mapapalaki sa mga HighDPI display. Pangalawa, may NameError na nagsasabing hindi naidineklara ang "birthday_entry".

Para malutas ang unang problema, maaring baguhin ang code na ito:

Python:
from tkinter import PhotoImage

Sa:

Python:
from customtkinter.widgets.ctk_image import CTkImage

At upang magamit ang CTkLabel, palitan ang code na ito:

Python:
info_label = ctk.CTkLabel(master=user_info_win, text=f"User Information for {username}", font=('Century Gothic', 16))

Sa:

Python:
image = CTkImage(file="vilo.gif")
info_label = ctk.CTkLabel(master=user_info_win, image=image, font=('Century Gothic', 16))
info_label.image = image

Para maayos ang pangalawang problema, maaaring ilagay ang linya na ito bago ang def update_info():

Python:
name_entry = ctk.CTkEntry(master=update_info_win, width=250)
birthday_entry = ctk.CTkEntry(master=update_info_win, width=250)

Kapag natapos na ang mga pagbabago, ang code na buong-buo ay maaaring maging ganito:

```python
import tkinter
from tkinter import messagebox
from PIL import Image, ImageTk
from customtkinter.widgets.ctk_image import CTkImage
import customtkinter as ctk
import json


reg_win = None # Declare reg_win as a global variable

def show_user_info_window(username, password, user_info):
global update_info_win, name_entry, age_entry, birthday_entry, email_entry

def update_info():
new_name = name_entry.get().strip()
new_age = age_entry.get().strip()
new_birthday = birthday_entry.get().strip()
new_email = email_entry.get().strip()

if not new_name or not new_age or not new_birthday or not new_email:
messagebox.showerror("Error", "Please fill all fields.")
return

user_info['Name'] = new_name
user_info['Age'] = new_age
user_info['Birthday'] = new_birthday
user_info['Email'] = new_email

# Update the displayed information
update_display()

messagebox.showinfo("Success", "Information updated successfully.")
update_info_win.destroy()

def update_display():
updated_info_text = f"Name: {user_info.get('Name', '')}\nAge: {user_info.get('Age', '')}\nBirthday: {user_info.get('Birthday', '')}\nEmail: {user_info.get('Email', '')}"
info_display.config(state=tkinter.NORMAL) # Enable editing
info_display.delete(1.0, tkinter.END)
info_display.insert(tkinter.END, updated_info_text)
info_display.config(state=tkinter.DISABLED) # Make it read-only

user_info_win = tkinter.Toplevel(app)
user_info_win.geometry("700x800")
user_info_win.title('User Information - GUI')

image = CTkImage(file="vilo.gif")
info_label = ctk.CTkLabel(master=user_info_win, image=image, font=('Century Gothic', 16))
info_label.image = image
info_label.pack(pady=10)

info_text = f"Name: {user_info.get('Name', '')}\nAge: {user_info.get('Age', '')}\nBirthday: {user_info.get('Birthday', '')}\nEmail: {user_info.get('Email', '')}"

info_display = tkinter.Text(master=user_info_win, font=('Century Gothic', 12), height=10, width=40)
info_display.insert(tkinter.END, info_text)
info_display.config(state=tkinter.DISABLED) # Make it read-only
info_display.pack(pady=10)

edit_button = ctk.CTkButton(master=user_info_win, text="Edit Information", width=20, command=lambda: edit_info())
edit_button.pack(pady=10)

def edit_info():
global update_info_win, name_entry, age_entry, birthday_entry, email_entry
update_info_win = tkinter.Toplevel(app)
update_info_win.geometry("700x800")
update_info_win.title('Edit Information - GUI')

name_label = ctk.CTkLabel(master=update_info_win, text="Name:", font=('Century Gothic', 12))
name_label.pack(pady=5)
name_entry = ctk.CTkEntry(master=update_info_win, width=250)
name_entry.insert(0, user_info.get('Name', ''))
name_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

age_label = ctk.CTkLabel(master=update_info_win, text="Age:", font=('Century Gothic', 12))
age_label.pack(pady=5)
age_entry = ctk.CTkEntry(master=update_info_win, width=250)
age_entry.insert(0, user_info.get('Age', ''))
age_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

birthday_label = ctk.CTkLabel(master=update_info_win, text="Birthday:", font=('Century Gothic', 12))
birthday_label.pack(pady=5)
birthday_entry = ctk.CTkEntry(master=update_info_win, width=250)
birthday_entry.insert(0, user_info.get('Birthday', ''))
birthday_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

email_label = ctk.CTkLabel(master=update_info_win, text="Email:", font=('Century Gothic', 12))
email_label.pack(pady=5)
email_entry = ctk.CTkEntry(master=update_info_win, width=250)
email_entry.insert(0, user_info.get('Email', ''))
email_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

update_button = ctk.CTkButton(master=update_info_win, text="Update", width=20, command=update_info)
update_button.pack(pady=10)



def open_registration_window():
global reg_win, entry3, entry4, entry5, entry6, entry7, entry8

print("Open Registration Window")
reg_win = tkinter.Toplevel(app)
reg_win.geometry("700x800")
reg_win.title('Registration - GUI')

entry3 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Username')
entry3.place(x=50, y=135)

entry4 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Password', show="*")
entry4.place(x=50, y=180)

entry5 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Full Name')
entry5.place(x=50, y=245)

entry6 = ctk.CTkEntry(master=reg_win
 
Ang error na iyong binigay ay may dalawang bahagi. Una, may UserWarning na nagpapahiwatig na ang larawan na ibinigay ay hindi isang CTkImage kundi isang tkinter.PhotoImage. Ibig sabihin, ang larawan ay hindi mapapalaki sa mga HighDPI display. Pangalawa, may NameError na nagsasabing hindi naidineklara ang "birthday_entry".

Para malutas ang unang problema, maaring baguhin ang code na ito:

Python:
from tkinter import PhotoImage

Sa:

Python:
from customtkinter.widgets.ctk_image import CTkImage

At upang magamit ang CTkLabel, palitan ang code na ito:

Python:
info_label = ctk.CTkLabel(master=user_info_win, text=f"User Information for {username}", font=('Century Gothic', 16))

Sa:

Python:
image = CTkImage(file="vilo.gif")
info_label = ctk.CTkLabel(master=user_info_win, image=image, font=('Century Gothic', 16))
info_label.image = image

Para maayos ang pangalawang problema, maaaring ilagay ang linya na ito bago ang def update_info():

Python:
name_entry = ctk.CTkEntry(master=update_info_win, width=250)
birthday_entry = ctk.CTkEntry(master=update_info_win, width=250)

Kapag natapos na ang mga pagbabago, ang code na buong-buo ay maaaring maging ganito:

```python
import tkinter
from tkinter import messagebox
from PIL import Image, ImageTk
from customtkinter.widgets.ctk_image import CTkImage
import customtkinter as ctk
import json


reg_win = None # Declare reg_win as a global variable

def show_user_info_window(username, password, user_info):
global update_info_win, name_entry, age_entry, birthday_entry, email_entry

def update_info():
new_name = name_entry.get().strip()
new_age = age_entry.get().strip()
new_birthday = birthday_entry.get().strip()
new_email = email_entry.get().strip()

if not new_name or not new_age or not new_birthday or not new_email:
messagebox.showerror("Error", "Please fill all fields.")
return

user_info['Name'] = new_name
user_info['Age'] = new_age
user_info['Birthday'] = new_birthday
user_info['Email'] = new_email

# Update the displayed information
update_display()

messagebox.showinfo("Success", "Information updated successfully.")
update_info_win.destroy()

def update_display():
updated_info_text = f"Name: {user_info.get('Name', '')}\nAge: {user_info.get('Age', '')}\nBirthday: {user_info.get('Birthday', '')}\nEmail: {user_info.get('Email', '')}"
info_display.config(state=tkinter.NORMAL) # Enable editing
info_display.delete(1.0, tkinter.END)
info_display.insert(tkinter.END, updated_info_text)
info_display.config(state=tkinter.DISABLED) # Make it read-only

user_info_win = tkinter.Toplevel(app)
user_info_win.geometry("700x800")
user_info_win.title('User Information - GUI')

image = CTkImage(file="vilo.gif")
info_label = ctk.CTkLabel(master=user_info_win, image=image, font=('Century Gothic', 16))
info_label.image = image
info_label.pack(pady=10)

info_text = f"Name: {user_info.get('Name', '')}\nAge: {user_info.get('Age', '')}\nBirthday: {user_info.get('Birthday', '')}\nEmail: {user_info.get('Email', '')}"

info_display = tkinter.Text(master=user_info_win, font=('Century Gothic', 12), height=10, width=40)
info_display.insert(tkinter.END, info_text)
info_display.config(state=tkinter.DISABLED) # Make it read-only
info_display.pack(pady=10)

edit_button = ctk.CTkButton(master=user_info_win, text="Edit Information", width=20, command=lambda: edit_info())
edit_button.pack(pady=10)

def edit_info():
global update_info_win, name_entry, age_entry, birthday_entry, email_entry
update_info_win = tkinter.Toplevel(app)
update_info_win.geometry("700x800")
update_info_win.title('Edit Information - GUI')

name_label = ctk.CTkLabel(master=update_info_win, text="Name:", font=('Century Gothic', 12))
name_label.pack(pady=5)
name_entry = ctk.CTkEntry(master=update_info_win, width=250)
name_entry.insert(0, user_info.get('Name', ''))
name_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

age_label = ctk.CTkLabel(master=update_info_win, text="Age:", font=('Century Gothic', 12))
age_label.pack(pady=5)
age_entry = ctk.CTkEntry(master=update_info_win, width=250)
age_entry.insert(0, user_info.get('Age', ''))
age_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

birthday_label = ctk.CTkLabel(master=update_info_win, text="Birthday:", font=('Century Gothic', 12))
birthday_label.pack(pady=5)
birthday_entry = ctk.CTkEntry(master=update_info_win, width=250)
birthday_entry.insert(0, user_info.get('Birthday', ''))
birthday_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

email_label = ctk.CTkLabel(master=update_info_win, text="Email:", font=('Century Gothic', 12))
email_label.pack(pady=5)
email_entry = ctk.CTkEntry(master=update_info_win, width=250)
email_entry.insert(0, user_info.get('Email', ''))
email_entry.pack(pady=5, side=tkinter.TOP, anchor=tkinter.CENTER)

update_button = ctk.CTkButton(master=update_info_win, text="Update", width=20, command=update_info)
update_button.pack(pady=10)



def open_registration_window():
global reg_win, entry3, entry4, entry5, entry6, entry7, entry8

print("Open Registration Window")
reg_win = tkinter.Toplevel(app)
reg_win.geometry("700x800")
reg_win.title('Registration - GUI')

entry3 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Username')
entry3.place(x=50, y=135)

entry4 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Password', show="*")
entry4.place(x=50, y=180)

entry5 = ctk.CTkEntry(master=reg_win, width=220, placeholder_text='Full Name')
entry5.place(x=50, y=245)

entry6 = ctk.CTkEntry(master=reg_win
Meron paring error ito: File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 12
global update_info_win, name_entry, age_entry, birthday_entry, email_entry
^
IndentationError: expected an indented block
 
Back
Top