Hi All i hope You had a fantastic day . i have code that in that code i made an Entry box
for Searching with Button it was made that for example if we click the search button while we wrote the correct name or family name we have to see the result of search but it doesnt work!
MyCode:
from tkinter import *
from tkinter import ttk
UserData = []
# Customize
Screen = Tk()
Screen.title("Test")
Screen.geometry("%dx%d+%d+%d" % (900, 450, 200, 200))
Screen.resizable(False, False)
# String Variable
name = StringVar()
family = StringVar()
# Functions
def BtnEnable(e):
if Name.get() and Family.get() != "":
Register.configure(state=NORMAL)
UserData.append(e)
return True
else:
Register.configure(state=DISABLED)
return False
def Delete(e):
for item in e:
item.set("")
def Clear():
NAME = Name.get()
FAMILY = Family.get()
us = {"name": NAME, "family": FAMILY}
result = BtnEnable(us)
if result:
list = [name, family]
insert(list)
Delete(list)
Name.focus_set()
def insert(value):
tbl.insert('', "end", values=[value[0].get(), value[1].get()])
def Select(value):
selection_row = tbl.selection()
if selection_row != ():
name.set(tbl.item(selection_row)["values"][0])
family.set(tbl.item(selection_row)["values"][1])
def Search(value):
SecondList = []
for item in UserData:
if ["name"] == value or ["family"] == value:
SecondList.append(item)
return SecondList
def SearchClicked():
query = search.get()
result = Search(query)
def EraseAndAdd(value):
for item in tbl.get_children():
sel = str(item, )
tbl.delete(sel)
for item in value:
tbl.insert('', "end", values=[item["name"], item["family"]])
# Label
Label(Screen, text="Name:", font="normal 20 bold").place(x=300, y=100)
Label(Screen, text="FamilyName:", font="normal 20 bold").place(x=300, y=150)
# Entry
Name = Entry(Screen)
Name.bind("<KeyRelease>", BtnEnable)
Name.configure(width=20, justify="right", textvariable=name)
Name.place(x=390, y=110)
Family = Entry(Screen)
Family.bind("<KeyRelease>", BtnEnable)
Family.configure(width=20, justify="right", textvariable=family)
Family.place(x=480, y=160)
search = Entry(Screen)
search.configure(width=20)
search.place(x=160, y=50)
# Button
Register = Button(Screen, text="Register")
Register.configure(bg="aqua", font="normal 20 bold", state=DISABLED, command=Clear)
Register.place(x=300, y=300)
SearchButton = Button(Screen, text="Search")
SearchButton.configure(bg="gray", font="normal 20 bold", command=SearchClicked)
SearchButton.place(x=160, y=90)
# Tabel
tbl = ttk.Treeview(Screen, columns="c1, c2", show="headings")
tbl.bind("<Button-1>", Select)
tbl.column("# 1", width=50)
tbl.heading("# 1", text="Name")
tbl.column("# 2", width=90)
tbl.heading("# 2", text="FamilyName")
tbl.pack(side=LEFT, fill=BOTH)
Screen.mainloop()
this is all of my code and i have to say that i dont get any errors but my program doesnt work while i click on search button
if you help me i really Appreciate it
have an awsome day