
trv.delete(selected_item)
##### Listing users with select and delete ###
def user_list():
my_w_child3=Toplevel(my_w) # Child window
my_w_child3.geometry("300x300") # Size of the window
my_w_child3.title("www.plus2net.com")
from tkinter import messagebox as msg
# display the list
def my_show():
r_set=my_conn.execute('''SELECT * from mem LIMIT 0,10''');
trv=ttk.Treeview(my_w_child3,selectmode='browse')
trv.grid(row=1,column=1,padx=20,pady=20)
trv["columns"]=("1","2","3","4")
trv['show']='headings'
trv.column("1",width=30,anchor='c')
trv.column("2",width=80,anchor='c')
trv.column("3",width=80,anchor='c')
trv.column("4",width=80,anchor='c')
trv.heading("1",text="id")
trv.heading("2",text="Name")
trv.heading("3",text="Userid")
trv.heading("4",text="Password")
for dt in r_set:
trv.insert("",'end',iid=dt[0],
values=(dt[0],dt[1],dt[2],dt[3]))
b1 = tk.Button(my_w_child3, text='delete row', width=20,bg='yellow',command=lambda: delete())
b1.grid(row=2,column=1)
def delete():
selected_item = trv.selection()[0]
my_var=msg.askyesnocancel("Delete ?","Delete id:"+str(selected_item),icon='warning',default='no',parent=my_w_child3)
if my_var: # True if yes button is clicked
query="DELETE FROM mem WHERE id=%s"
rs=my_conn.execute(query,selected_item)
if(rs.rowcount==1):
trv.delete(selected_item)
msg.showerror("Deleted ","No of records deleted = " + str(rs.rowcount),parent=my_w_child3)
#my_conn.commit()
my_show()
There are other two parts, one for listing and other for registration. CREATE TABLE IF NOT EXISTS `mem` (
`id` int(3) NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT '',
`userid` varchar(15) CHARACTER SET utf8 NOT NULL DEFAULT '',
`password` varchar(20) NOT NULL DEFAULT '',
UNIQUE KEY `id` (`id`),
UNIQUE KEY `usrid` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--
-- Dumping data for table `mem`
--
INSERT INTO `mem` (`id`, `name`, `userid`, `password`) VALUES
(1, 'smo1', 'smo123', 'test123'),
(2, 'smo2', 'smo213', 'test213'),
(3, 'smo3', 'smo312', 'test312');
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.