39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import tkinter as tk
|
|
|
|
def tk_04():
|
|
"""Create a window that will ask the user to enter a name in a text box.
|
|
When they click on a button it will add it to the end of the list that is
|
|
displayed on the screen. Create another button which will clear the list."""
|
|
def click():
|
|
name = txt_in_box.get()
|
|
if name != "":
|
|
lst_names.insert('end', name)
|
|
txt_in_box.delete(0, 'end')
|
|
txt_in_box.focus()
|
|
|
|
def reset():
|
|
lst_names.delete(0, 'end')
|
|
txt_in_box.focus()
|
|
|
|
window = tk.Tk()
|
|
window.title("Lista TK")
|
|
window.geometry("390x350")
|
|
|
|
lbl_info = tk.Label(text="Ingresa un nombre: ")
|
|
lbl_info.place(x=40, y=25, width=150, height=35)
|
|
|
|
txt_in_box = tk.Entry()
|
|
txt_in_box["justify"] = "center"
|
|
txt_in_box.place(x=180, y=25, width=150, height=35)
|
|
txt_in_box.focus()
|
|
|
|
btn_add = tk.Button(text="Agregar", command=click)
|
|
btn_add.place(x=40, y=75, width=150, height=35)
|
|
btn_reset = tk.Button(text="Vaciar", command=reset)
|
|
btn_reset.place(x=190, y=75, width=150, height=35)
|
|
|
|
lst_names = tk.Listbox()
|
|
lst_names.place(x=40, y=120, width=300, height=200)
|
|
|
|
window.mainloop()
|