tkinter_战队数据查询系统

# 导入tkinter模块
import tkinter
from tkinter import ttk
# 导入库
import pymysql




# 创建主窗口对象
root = tkinter.Tk()
# 设置初始化界面大小
root.geometry('520x300')
# 窗口标题
root.title("战队数据查询系统")

# 标签控件:选择战队
xuanze = tkinter.Label(root,text = '选择战队')
xuanze.place(x = 130,y = 20)
xuanze = tkinter.Label(root,text = '排      名:')
xuanze.place(x = 130,y = 90)
xuanze = tkinter.Label(root,text = '战队名称:')
xuanze.place(x = 130,y = 110)
xuanze = tkinter.Label(root,text = 'K   D   A:')
xuanze.place(x = 130,y = 130)
xuanze = tkinter.Label(root,text = '场均击杀:')
xuanze.place(x = 130,y = 150)
xuanze = tkinter.Label(root,text = '场均死亡:')
xuanze.place(x = 130,y = 170)
xuanze = tkinter.Label(root,text = '参赛次数:')
xuanze.place(x = 130,y = 190)
xuanze = tkinter.Label(root,text = '胜  /   负:')
xuanze.place(x = 130,y = 210)
xuanze = tkinter.Label(root,text = '胜      率:')
xuanze.place(x = 130,y = 230)


# 创建下拉菜单
cmb = ttk.Combobox(root)
cmb.place(x = 200,y = 20)
# 下拉菜单中的值
cmb['value'] = ('FPX','TES','RNG','BLG','EDG','IG','SN','LNG','WE','JDG','DMO','RW','V5','LGD','VG','OMG')
# 下拉列表默认值
cmb.current(0)

# 定义变量类型
var_zhandui = tkinter.StringVar()
cd_1 = tkinter.StringVar()
cd_2 = tkinter.StringVar()
cd_3 = tkinter.StringVar()
cd_4 = tkinter.StringVar()
cd_5 = tkinter.StringVar()
cd_6 = tkinter.StringVar()
cd_7 = tkinter.StringVar()
cd_8 = tkinter.StringVar()
# 查询函数
def xuanze():
    # 创建连接
    conn = pymysql.connect(host='localhost', user='root', password='fuqian1314', database='wdc')
    # 得到一个可以执行SQL语句的光标对象
    cursor = conn.cursor()
    var_zhandui = cmb.get()
    # print(var_zhandui)
    sql = 'select * from lol where name = "%s"' %(var_zhandui)
    cursor.execute(sql)
    result = cursor.fetchall()
    # print(result)

    # 关闭光标对象
    cursor.close()
    # 关闭数据库连接
    conn.close()

    # print(result[0][0],result[0][1],result[0][2],result[0][3],result[0][4],result[0][11],result[0][12],result[0][13])
    cd_1 = result[0][0]
    cd_2 = result[0][1]
    cd_3 = result[0][2]
    cd_4 = result[0][3]
    cd_5 = result[0][4]
    cd_6 = result[0][11]
    cd_7 = result[0][12]
    cd_8 = result[0][13]
    # print(cd_1)
    xianshi = tkinter.Listbox(root,height = 8,width = 30)
    xianshi.place(x = 200,y = 100)
    # cd = [cd_1,cd_2,cd_3,cd_4,cd_5,cd_6,cd_7,cd_8]
    xianshi.insert("end",cd_1,cd_2,cd_3,cd_4,cd_5,cd_6,cd_7,cd_8)


# 查询按钮
qveding = tkinter.Button(root,text = '查询',command = xuanze)
qveding.place(x = 400,y = 20)

huabu = tkinter.Text(root,height = 11,width = 30)
huabu.place(x = 200,y = 100)


# 加入消息循环
root.mainloop()

效果展示:

1.

2.

posted @ 2019-09-16 11:03  手可摘星辰。  阅读(761)  评论(0编辑  收藏  举报