Hello
i made a python tkinter project.
my project is a register panel and in this panel i have a tabel with three
columns called name familyname and age but in this position if i enter 1 name twice
(i mean for example if i entered martin name once and i again enter martin name) my
program adds the instructions again although i entered them once
from tkinter import ttk
from tkinter import *
from tkinter import messagebox
UserData = []
# Customize
Screen = Tk()
Screen.title("Panel")
Screen.iconbitmap("icon/icon.ico")
Screen.geometry("%dx%d+%d+%d" % (600, 300, 200, 200))
Screen.resizable(False, False)
# String Variable
name = StringVar()
family = StringVar()
age = StringVar()
# Function
def register(user):
if int(user["age"]) < 18:
messagebox.showerror("Error", "Your too Young")
else:
messagebox.showinfo("info", "Done!")
UserData.append(user)
return True
def Delete(e):
for item in e:
item.set("")
def RegisterClicked():
NAME = name.get()
FAMILY = family.get()
AGE = age.get()
if name.get() == "" or family.get() == "" or age.get() == "":
messagebox.showwarning("Warning!", "please enter all of your instructions")
return
us = {"name": NAME, "family": FAMILY, "age": AGE}
result = register(us)
if result:
list = [name, family, age]
InsertData(list)
Delete(list)
Name.focus_set()
def InsertData(value):
tbl.insert('', "end", value=[value[0].get(), value[1].get(), value[2].get()])
def Select(e):
selection_row = tbl.selection()
if selection_row != ():
name.set(tbl.item(selection_row)["values"][0])
family.set(tbl.item(selection_row)["values"][1])
age.set(tbl.item(selection_row)["values"][2])
def Search(value):
SecondList = []
for item in UserData:
if item["name"] == value or item["family"] == value or item["age"] == value:
SecondList.append(item)
return SecondList
def SearchClicked():
query = search.get()
result = Search(query)
Clean()
Load(result)
def Clean():
for item in tbl.get_children():
sel=(str(item),)
tbl.delete(sel)
def Load(value):
for item in value:
tbl.insert('', "end", value=[item["name"], item["family"], item["age"]])
# Label
Label(Screen, text="Name:", font="normal 20 bold").place(x=0, y=0)
Label(Screen, text="FamilyName:", font="normal 20 bold").place(x=0, y=50)
Label(Screen, text="Age:", font="normal 20 bold").place(x=0, y=100)
# Entry
Name = Entry(Screen)
Name.configure(width=20, textvariable=name)
Name.place(x=90, y=10)
Family = Entry(Screen)
Family.configure(width=20, textvariable=family)
Family.place(x=180, y=60)
Age = Entry(Screen)
Age.configure(width=20, textvariable=age)
Age.place(x=90, y=110)
search = Entry(Screen)
search.configure(width=20)
search.place(x=160, y=205)
# Button
Register = Button(Screen, text="Register")
Register.configure(font="normal 10 bold", bg="gray", command=RegisterClicked)
Register.place(x=0, y=170)
SearchButton = Button(Screen, text="Search")
SearchButton.configure(font="normal 10 bold", bg="gray", command=SearchClicked)
SearchButton.place(x=100, y=200)
# Tabel
tbl = ttk.Treeview(Screen, columns="c1, c2, c3", 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.column("# 3", width=50)
tbl.heading("# 3", text="Age")
tbl.pack(side=RIGHT, fill=BOTH)
Screen.mainloop()
this is all of my code
as you can see in the photo that i send you can see the john mactavish with 23 year
old is there again and i just want to make a script that it works like if all of instructionss were the same messagebox show something
i realy appreciate it if you help me