import tkinter as tk import pymysql

class MyApp: def init(self): self.window = tk.Tk() self.herdid_t = tk.StringVar() self.herdname_t = tk.StringVar() self.creattime_t = tk.StringVar()

    tk.Label(self.window, text='herdid').grid(row=0, column=0)
    tk.Label(self.window, text='herdname').grid(row=1, column=0)
    tk.Label(self.window, text='creattime').grid(row=2, column=0)

    self.herdid_entry = tk.Entry(self.window, textvariable=self.herdid_t)
    self.herdid_entry.grid(row=0, column=1)
    self.herdname_entry = tk.Entry(self.window, textvariable=self.herdname_t)
    self.herdname_entry.grid(row=1, column=1)
    self.creattime_entry = tk.Entry(self.window, textvariable=self.creattime_t)
    self.creattime_entry.grid(row=2, column=1)

    self.select_button = tk.Button(self.window, text='查询', command=self.select)
    self.select_button.grid(row=3, columnspan=2)

    self.result_label = tk.Label(self.window, text='')
    self.result_label.grid(row=4, columnspan=2)

def select(self):
    db = pymysql.connect(host='localhost', user='root', password='111111', port=3306, db='student', charset='utf8')
    cursor = db.cursor()
    sql = f"SELECT * FROM pigherd WHERE herdid='{self.herdid_t.get()}' OR herdname='{self.herdname_t.get()}' OR creattime='{self.creattime_t.get()}'"
    cursor.execute(sql)
    result = cursor.fetchone()
    self.result_label.config(text=result)
    db.close()

def run(self):
    self.window.mainloop()

检查代码

内容:The code appears to be correct and does not have any syntax errors.


原文地址: http://www.cveoy.top/t/topic/pNCq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录