[Python] how can i add entry boxes and other widgets to the window from outside of the...

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a main window and made a pop-up window 'logwind' inside of the function 'log_window'. I want to add entry boxes to the window from outside the function but I keep getting a Name error. How can I code this so that I can make changes to the window from outside the function?

    from tkinter import *
    import tkinter.messagebox as box


    tscreen = Tk()
    tscreen.title("welcome to revise biology")
    # sets window size
    tscreen.geometry("1600x1024")

    # insert my picture
    # reads the image
    image = Image.open("C:/Users/Amara/Downloads/pixel_art (1).png")
    resize_img = image.resize((1300,700))
    img = ImageTk.PhotoImage(resize_img)
    # to show image
    label1 = Label(image = img)
    label1.image = img
    label1.pack()

    #adds text to the screen
    label2 = Label(tscreen, text="welcome to revise
    biology",bg="#e6d192")
    label2.config(font=("Courier New",15))
    label2.place(x=480,y=80)


    def log_window():
    global logwind
    logwind = Toplevel(tscreen)
    logwind.title("login/sign in")
    logwind.geometry("600x400")
    sbg = Image.open("C:/Users/Amara/Downloads/pixel_art (3).png")
    sbg = sbg.resize((600, 400))
    sl_bg_img = ImageTk.PhotoImage(sbg)
    sl_label3 = Label(logwind, image = sl_bg_img)
    sl_label3.image = sl_bg_img
    sl_label3.pack()
    label4 = Label(logwind, text="please login or sign up to continue", bg= "#e6d192")
    label4.config(font=("Courier New", 10))
    label4.place(x=160, y=50)
    #return


    button1 = Button(label1, text="continue",bg= '#fce5cd', command=log_window)
    button1.place(x=580,y=250)
    button1.config(font=("Courier New",15))

    user_n = StringVar()
    pass_w = StringVar()

    def user_details():
    user = user_n.get()
    passw = pass_w.get()

    user_n.set("")
    pass_w.set("")

    #makes text and entry box visible in logwind window
    sign_up = Label(logwind, text="sign up")

    s_user_lab = Label(logwind,text = "username: ", font=("Courier New", 10))
    s_user_inp = Entry(logwind, textvariable= user_n, font=("Courier New", 10))

    pass_lab = Label(logwind, text = "password: ",font=("Courier New", 10))
    #makes text visible in logwind window and entry box made which displays each character
    #as asteriks

    pass_inp = Entry(logwind, textvariable= pass_w, show="*",font=("Courier New", 10))

    ud_button = Button(logwind, text ="enter")


    frame = Frame(log_window())
    entry = Entry(frame)






    tscreen.mainloop()


    title screen of my program, pop-up window that I would like my entry boxes to be on The 2nd picture is what I got before I started coding the entry boxes.

    Continue reading...

Compartilhe esta Página