0

I am working on a school project and i am very new to programming. I want to know how i can take the GUI i made which contains a set of entries/labels/buttons and make the window "refresh" as you would in a normal browser. My goal is to clear the window of all the entries and buttons during this "refresh".

I thank for any advice in advance and hope my post was specific enough.

Here is a login screen without any functions.

import tkinter
import distutils
from distutils.cmd import Command
import os
from _ast import Delete

window = tkinter. Tk()
window.title("PTF Pydev Eclipse")
window.geometry("500x500")

lbl = tkinter.Label(window, text= "Username")
ent = tkinter.Entry(window)
lbl1 = tkinter.Label(window, text= "Password")
ent1 = tkinter.Entry(window)
lbl2 = tkinter.Label(window, text= "Access")

ent1.bind('<Return>', show) # Not sure if this is needed
btn = tkinter.Button(window, text="Login", command= lambda: validation())

lbl.pack()
ent.pack()
lbl1.pack()
ent1.pack()
lbl2.pack()
btn.pack()

window.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
John David
  • 11
  • 4

1 Answers1

0

You can use pack_forget() to remove widget.

lbl.pack_forget()
ent.pack_forget()
lbl1.pack_forget()
ent1.pack_forget()
lbl2.pack_forget()
btn.pack_forget()

You can also put all widgets in Frame() and then use pack_forget() to remove Frame with all widgets inside.

import tkinter as tk

def validation():
    # remove frame
    frame.pack_forget()

window = tk.Tk()
window.title("PTF Pydev Eclipse")
window.geometry("500x500")

# create frame
frame = tk.Frame(window)
frame.pack()

# put widgets in frame 
lbl = tk.Label(frame, text= "Username")
ent = tk.Entry(frame)
lbl1 = tk.Label(frame, text= "Password")
ent1 = tk.Entry(frame)
lbl2 = tk.Label(frame, text= "Access")

#ent1.bind('<Return>', show) # Not sure if this is needed
btn = tk.Button(frame, text="Login", command=validation)

ent.pack()
lbl1.pack()
ent1.pack()
lbl2.pack()
btn.pack()

window.mainloop()

BTW: it can be useful: "famous" Bryan Oakley's program on how to switch between frames.

Community
  • 1
  • 1
furas
  • 134,197
  • 12
  • 106
  • 148
  • thank you very much the suggested "forget" helped very much with the problem and the link helped me immensely in understanding the connection of the "parent/child" parameters. – John David Feb 02 '16 at 12:50