Python不升级tab

2024-10-04 05:31:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python做数据库GUI应用程序,但我不能更新表。没有错误,但我运行程序后,我看Mysql工作台没有任何变化

class DB:
    def __init__(self):
        self.conn = mysql.connector.connect(host='localhost',                                                   database='databese', user='user',                                              
         password='password')
        self.cur = self.conn.cursor()
        self.conn.commit()

    def update(self, isim):
        self.conn.commit()
        self.cur.execute("UPDATE hakemler SET durum='UYGUNSUZ' WHERE isim='%s' ",isim)

    def updateback(self, isim):
        self.cur.execute("UPDATE hakemler SET durum='UYGUN' WHERE isim='%s'",isim)
        self.conn.commit()
db = DB()

def çıkar():
    db.update(id.get())
def gerial():
    db.updateback(hakem1.get())
hakem = StringVar()
hakem1= StringVar()
id  = IntVar()
entry1 = tk.Entry(mazeretli, width=20, textvariable=id)
entry1.grid(row=1, column=1)
button1 = tk.Button(mazeretli, text="Kişiyi Listeden Çıkar", command=çıkar)
button1.grid(row=2, column=2)
entry2 = tk.Entry(mazeretli, width=20, textvariable=hakem1)
entry2.grid(row=3, column=1)
button2 = tk.Button(mazeretli, text="Kişiyi Geri Al", command=gerial)
button2.grid(row=4, column=2)

没有错,梅塞格斯什么的。代码就是不起作用


Tags: selfiddbdefcolumnconntkgrid
1条回答
网友
1楼 · 发布于 2024-10-04 05:31:02

你的问题是:

def update(self, isim):
    self.conn.commit()
    self.cur.execute("UPDATE hakemler SET durum='UYGUNSUZ' WHERE isim='%s' ",isim)

数据库操作要求在操作之后commit,以便将更改写入数据库。你把顺序颠倒了。替换订单:

def update(self, isim):
    self.cur.execute("UPDATE hakemler SET durum='UYGUNSUZ' WHERE isim='%s' ",isim)
    self.conn.commit()

相关问题 更多 >