0

嗨ٍ每个兄弟我有一个关于我的新程序的问题,这是我正在写的电话簿,我的问题是关于检查按钮和按钮,我想从我制作的数据库中制作一个带有姓名和家庭地址的号码列表此列表有每个数字的 1 个复选按钮和两个用于编辑和删除的按钮现在我正在寻找一种方法来了解列表中的所有这些复选按钮和按钮如何相互连接,这意味着列表中数据库中的每条记录都带有一个复选按钮和Buttons For That Be In One Conection That When That Checkbutton Is Selected These To Buttons For Edit And Delete Work For That Record From Database So We Have To Conection Here Every Record In This List Need To Be Conect With Checkbutton And Buttons To Operate On It And数据库中的这种变化见。

from sqlite3.dbapi2 import enable_callback_tracebacks
from tkinter import *
from tkinter import ttk
import sqlite3
from tkinter import messagebox
from typing import Sized
from PIL import ImageTk, Image


win = Tk()

win.geometry("1250x800")

win.title('PhoneBook Of Manoochehr')

win.iconbitmap('icon.ico')

s = list

my_pic = Image.open('pic4.jpg')

resized = my_pic.resize((1250,800),Image.ANTIALIAS)

new_pic = ImageTk.PhotoImage(resized)

my_label = Label(win, image=new_pic)
my_label.pack()


lb = Label(win, text='Name', font=5)
lb.place(x=900, y=40)

en = Entry(win , width = 60, bd = 3, font=('Arial', 15) )
en.place(x = 225, y = 42)

lb1 = Label(win, text='Familly :', font=5)
lb1.place(x=835, y=90)

en1 = Entry(win , width = 60 , bd = 3, font=('Arial', 15) )
en1.place(x=160 , y=93)

lb2 = Label(win, text='Number :', font=5)
lb2.place(x=840, y=195)

en2 = Entry(win , width = 60 , bd = 3, font=('Arial', 15) )
en2.place(x = 160 , y = 195)

lb3 = Label(win, text='Address :', font=5)
lb3.place(x=885, y=245)

en3 = Entry(win , width = 65, bd = 3, font=('Arial', 15))
en3.place(x = 150 , y = 246)

def savebtn():
    connection = sqlite3.connect('DBphonebook.db')
    c = connection.cursor()
    c.execute("INSERT INTO phonebook(Name, Familly, Number, Address) 
    VALUES('%s', '%s', '%s', '%s')"
    %(en.get(), en1.get(), en2.get(), en3.get()))
    connection.commit()
    connection.close()
    messagebox.showinfo("Success" , "Done!")
    en.delete(0, END)
    en1.delete(0, END)
    en2.delete(0, END)
    en3.delete(0, END)

btn = Button(win, text='Save', padx=50, pady=10, font=20, 
background='pink', command=savebtn)
btn.place(x= 700, y=350)



def clear_edit_btn():
    global s
    connection = sqlite3.connect('DBphonebook.db')
    c = connection.cursor()
    search = c.execute('SELECT * FROM phonebook')
    s = list(search)
    x = 0
    top1 = Toplevel()
    top1.geometry("1250x800")
    top1.title('Edit And Delete')
    main_frame = Frame(top1)
    main_frame.pack(fill=BOTH, expand=1, pady=50)
    my_canvas = Canvas(main_frame)
    my_canvas.pack(side=LEFT, fill=BOTH, expand=1)
    my_scrollbar = ttk.Scrollbar(main_frame, orient=VERTICAL, 
    command=my_canvas.yview)
    my_scrollbar.pack(side=RIGHT, fill=Y)
    my_canvas.configure(yscrollcommand=my_scrollbar.set)
    my_canvas.bind('<Configure>', lambda e: 
    my_canvas.configure(scrollregion=my_canvas.bbox("all")))
    second_frame = Frame(my_canvas)
    second_frame.configure(background='GREEN')
    my_canvas.create_window((0,0), window=second_frame, anchor="nw")
    lbl = Label(top1, text='Address', font=5)
    lbl.place(x=495, y=15)
    lbl = Label(top1, text='Number', font=5)
    lbl.place(x=870, y=15)
    lbl = Label(top1, text='Familly', font=5)
    lbl.place(x=990, y=15)
    lbl = Label(top1, text='Name', font=5)
    lbl.place(x=1145, y=15)


def deletebtn(arg):
    global s
    a = 0
    a += 1
    for j in s:    
        if arg == a:
            connection = sqlite3.connect('DBphonebook.db')
            c = connection.cursor()
            c.execute("DELETE from phonebook WHERE Name= :Name AND Familly= 
            :Familly AND Number= :Number AND Address= :Address",
            {'Name':j[0], 'Familly':j[1], 'Number':j[2], 'Address':j[3]})
            connection.commit()
            connection.close()



 



    b = 0
    for i in s:
        b += 1
        x += 20
        Button(second_frame, text='Edit', bd=3).grid(row=x, column=100, 
        pady=10, padx=10)
        Button(second_frame, text='Delete', bd=3, command=lambda: 
        deletebtn(b)).grid(row=x, column=50, pady=10, padx=10)
        Checkbutton(second_frame).grid(row=x, column=0, pady=10, padx=10)
        lb = Label(second_frame, text=i[3]).grid(row=x, column=150, 
        pady=10, padx=130)
        lb = Label(second_frame, text=i[2]).grid(row=x, column=200, 
        pady=10, padx=30)
        lb = Label(second_frame, text=i[0]).grid(row=x, column=300, 
        pady=10, padx=30)
        lb = Label(second_frame, text=i[1]).grid(row=x, column=250, 
        pady=10, padx=30)


        btn1 = Button(win, text='List , Edit And Delete', padx=50, pady=10, 
        font=20, background='pink', command=clear_edit_btn)
        btn1.place(x= 300, y=350)

win.mainloop()
4

0 回答 0