I'm trying to clear my entry boxes in the new window, but it doesn't work. Can somebody help me to solve this problem? Here is my code below.
from tkinter import *
from tkinter import ttk
def new_deal():
def add_new_deal():
for each_entry in entry:
each_entry.delete(0, END)
def close_new_deal():
new_deal_window.destroy()
button_new_deal['state'] = 'normal'
def user_input():
symbol_label = Label(new_deal_window, text="Ticker")
symbol_label.place(x=10, y=50)
screener_label = Label(new_deal_window, text="Screener")
screener_label.place(x=10, y=80)
exchange_label = Label(new_deal_window, text="Exchange")
exchange_label.place(x=10, y=110)
number_label = Label(new_deal_window, text="Number")
number_label.place(x=10, y=140)
sum_label = Label(new_deal_window, text="Sum")
sum_label.place(x=10, y=170)
symbol_entry = Entry(new_deal_window)
symbol_entry.place(x=100, y=50)
screener_entry = Entry(new_deal_window)
screener_entry.place(x=100, y=80)
exchange_entry = Entry(new_deal_window)
exchange_entry.place(x=100, y=110)
number_entry = Entry(new_deal_window)
number_entry.place(x=100, y=140)
sum_entry = Entry(new_deal_window)
sum_entry.place(x=100, y=170)
return symbol_entry, screener_entry, exchange_entry, number_entry, sum_entry
button_new_deal['state'] = ['disabled']
new_deal_window = Toplevel(main_window)
new_deal_window.geometry("400x500")
new_deal_window.title("New deal")
entry = user_input()
button_add_deal = Button(new_deal_window, text="Add deal", command=add_new_deal())
button_add_deal.pack()
new_deal_window.protocol("WM_DELETE_WINDOW", close_new_deal)
# Create main window
main_window = Tk()
main_window.geometry("1280x960")
main_window.title("Invest monitor")
icon = PhotoImage(file='clipart3605240.png')
main_window.iconphoto(True, icon)
# Create menubar
menubar = Menu(main_window)
main_window.config(menu=menubar)
program = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Program", menu=program)
program.add_command(label="Exit", command=quit)
program.add_command(label="About")
# Create notebook
notebook = ttk.Notebook(main_window)
investment_portfolio_tab = Frame(notebook)
plans_tab = Frame(notebook)
notebook.add(investment_portfolio_tab, text="Investment portfolio")
notebook.add(plans_tab, text="Plans")
notebook.pack(expand=True, fill="both")
# Create button New Deal
button_new_deal = Button(investment_portfolio_tab, text="New deal", command=new_deal)
button_new_deal.pack()
# Initialize
main_window.mainloop()
As you can see, I'm trying to create a new TopLevel window "new_deal_window" in the function "new_deal". In continue, i'm creating some labels and entry boxes (which are supposed to be filled with some value) in the function called "user_input", and then i would like to clear this values whit the button "button_add_deal".
In my opinion, i have some issues whit the type conversation, but i don't know where it is exactly.