Python编写MySQL管理工具 由Python编写的MySQL管理工具代码实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Python编写MySQL管理工具 由Python编写的MySQL管理工具代码实例

weixin_43614688   2021-03-30 我要评论


import pymysql
import pandas as pd
from tkinter import Label,StringVar,Entry,Tk,Button
from tkinter.simpledialog import askstring
def Entry_address():                        #输入数据库地址
  root=Tk()
  l1=Label(root,text='服务器:').grid(column=0,row=0)
  text1=StringVar()
  Entry(root,textvariable=text1).grid(column=1,row=0)
  l2=Label(root,text='用户名:').grid(column=0,row=1)
  text2=StringVar()
  Entry(root,textvariable=text2).grid(column=1,row=1)
  l3 = Label(root, text='密码').grid(column=0, row=2)
  text3 = StringVar()
  Entry(root, textvariable=text3,show='*').grid(column=1, row=2)
  l4 = Label(root, text='数据库').grid(column=0, row=3)
  text4 = StringVar()
  Entry(root, textvariable=text4).grid(column=1, row=3)
  Button(root,text='确定',command=lambda:root.destroy()).grid(column=1,row=4)
  root.mainloop()
  return text1.get(),text2.get(),text3.get(),text4.get()
def connect_database():                       #连接数据库
  h,u,p,d=Entry_address()
  connect = pymysql.connect(host=h, user=u, password=p, db=d)
  cursor = connect.cursor(cursor=pymysql.cursors.DictCursor)
  return cursor
def select_data():                         #操作数据
  cursor=connect_database()
  # query='insert into person (fname,lname) values(%s,%s)'
  # values=('lu','Cachy')##元组只能存储单一数据类型
  # cursor.execute(query,values)
  root1=Tk()
  root1.withdraw()
  query=askstring('hello','输入SQL语句')
  root1.destroy()
  root1.mainloop()
  cursor.execute(query)
  cursor.connection.commit()                   #获取权限
  a = cursor.fetchall()                      #从游标中取出数据
  cursor.close()
  c=pd.DataFrame(a)
  print(c)
if __name__=='__main__':
  select_data()

以上所述是小编给大家介绍的由Python编写的MySQL管理工具详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们