Python3.7+tkinter实现查询界面功能


Posted in Python onDecember 24, 2019

Tkinter 是 Python 的标准 GUI 库。Python 使用 Tkinter 可以快速的创建 GUI 应用程序。

这篇文章使用tkinter实现一个简单的查询界面

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from tkinter import *
import sqlite3
# 导入消息对话框子模块
import tkinter.messagebox
#import urllib
 #创建主窗口
root = Tk()
root.title('球员查询')
# 设置窗口大小
root.minsize(500,500)
#定义变量
name = StringVar()
name.set('')
club = StringVar()
club.set('')
nation = StringVar()
nation.set('')
height = StringVar()
height.set('')
position = StringVar()
position.set('')
age = StringVar()
age.set('')
weight = StringVar()
weight.set('')
num = StringVar()
num.set('')
birthday = StringVar()
birthday.set('')
habit = StringVar()
habit.set('')
#name text, club text, nation text, height text, position text, age text, weight text, num text, birthday text, habit text
le_name = Label(root, textvariable = name).place(x = 100, y = 80)  #姓 名
le_club = Label(root, textvariable = club).place(x = 100, y = 110)  #俱乐部
le_nation = Label(root, textvariable = nation).place(x = 100, y = 140)  #国籍
le_height = Label(root, textvariable = height).place(x = 100, y = 170)  #身高
le_position = Label(root, textvariable = position).place(x = 100, y = 200)  #位置
le_age = Label(root, textvariable = age).place(x = 100, y = 230)  #年龄
le_weight = Label(root, textvariable = weight).place(x = 100, y = 260)  #体重
le_num = Label(root, textvariable = num).place(x = 100, y = 290)  #出场数
le_birthday = Label(root, textvariable = birthday).place(x = 100, y = 320)  #生日
le_habit = Label(root, textvariable = habit).place(x = 100, y = 350)  #惯用脚
#查询按钮响应函数
def select(root, label):
 sname = label.get()
 print('input: ',sname)
 #查询刚才插入的数据
 #由于刚才已经关闭了数据库连接,需要重新创建Connection对象和Cursor对象
 conn = sqlite3.connect('dongqiudi.db')
 #c = conn.execute('''select * from footballers''')
 #c = conn.execute("select * from footballers where name like?",(sname,))
 print("select * from footballers where name like '%"+sname+"%'")
 c = conn.execute("select * from footballers where name like '%"+sname+"%'")
 #print(c) #<sqlite3.Cursor object at 0x00000000007E25E0>
 list_re = list(c)
 print('result: ', list_re) #[('艾克森', '15', 'ChOxM1xC0BiAe2D7AAAN-qiRteQ443.png')]
 if len(list_re) <= 0:
 tkinter.messagebox.showinfo('提示',sname+'球员不存在,请输入其他球员姓名!') 
 else:
 print('result_name: ', list_re[0][0])
 #数据成功提取出来了
 #name text, club text, nation text, height text, position text, age text, weight text, num text, birthday text, habit text
 name.set(list_re[0][0])  #姓 名
 club.set(list_re[0][1])  #俱乐部
 nation.set(list_re[0][2])  #国籍
 height.set(list_re[0][3])  #身高
 position.set(list_re[0][4])  #位置
 age.set(list_re[0][5])  #年龄
 weight.set(list_re[0][6])  #体重
 num.set(list_re[0][7])  #出场数
 birthday.set(list_re[0][8])  #生日
 habit.set(list_re[0][9])  #惯用脚
 conn.close()
#定义一个返回按钮调用的返回函数:callback
def exit_program():
 quit()
def main():
 input_name = Label(root, text = '请输入球员姓名:').place(x = 30, y = 30)
 label = StringVar()
 entry = Entry(root,bg='#ffffff',width=20,textvariable=label).place(x=130,y=30,anchor='nw')
 #按钮
 select_button = Button(root,bg='white',text='查询',width=10,height=1,
    command=lambda :select(root, label)).place(x=280,y=26,anchor='nw')
 exit_button = Button(root,bg='white',text='退出',width=10,height=1,
    command=lambda :exit_program()).place(x=380,y=26,anchor='nw')
 #command是Button中的option项,可以指定点击button时调用的callback函数
 #name text, club text, nation text, height text, position text, age text, weight text, num text, birthday text, habit text
 le_name = Label(root, text = '姓 名:').place(x = 40, y = 80)
 le_club = Label(root, text = '俱乐部:').place(x = 40, y = 110)
 le_naion = Label(root, text = '国 籍:').place(x = 40, y = 140)
 le_height = Label(root, text = '身 高:').place(x = 40, y = 170)
 le_positon = Label(root, text = '位 置:').place(x = 40, y = 200)
 le_age = Label(root, text = '年 龄:').place(x = 40, y = 230)
 le_weight = Label(root, text = '体 重:').place(x = 40, y = 260)
 le_num = Label(root, text = '号 码:').place(x = 40, y = 290)
 le_birthday = Label(root, text = '生 日:').place(x = 40, y = 320)
 le_habit = Label(root, text = '惯用脚:').place(x = 40, y = 350)
 #显示图片
 #pilImage = Image.open("imgs/1574777943.3190248.png")
 #tkImage = ImageTk.PhotoImage(image=pilImage)
 #label_nation = Label(root, image=tkImage).place(x=90, y=130, anchor='nw')
 root.mainloop()
main()

Python3.7+tkinter实现查询界面功能

总结

以上所述是小编给大家介绍的Python3.7+tkinter实现查询界面功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

Python 相关文章推荐
在python中的socket模块使用代理实例
May 29 Python
详解python之配置日志的几种方式
May 22 Python
Python判断文件或文件夹是否存在的三种方法
Jul 27 Python
Python 实现在文件中的每一行添加一个逗号
Apr 29 Python
django自带调试服务器的使用详解
Aug 29 Python
python可视化实现KNN算法
Oct 16 Python
Windows10下Tensorflow2.0 安装及环境配置教程(图文)
Nov 21 Python
Python2和Python3中@abstractmethod使用方法
Feb 04 Python
Python连接SQLite数据库并进行增册改查操作方法详解
Feb 18 Python
Django Session和Cookie分别实现记住用户登录状态操作
Jul 02 Python
Python编写可视化界面的全过程(Python+PyCharm+PyQt)
May 17 Python
python如何将mat文件转为png
Jul 15 Python
python 读取更新中的log 或其它文本方式
Dec 24 #Python
如何基于python操作excel并获取内容
Dec 24 #Python
python实现tail实时查看服务器日志示例
Dec 24 #Python
Python 模拟动态产生字母验证码图片功能
Dec 24 #Python
python中return的返回和执行实例
Dec 24 #Python
Python文件操作函数用法实例详解
Dec 24 #Python
Python的形参和实参使用方式
Dec 24 #Python
You might like
js使用post 方式打开新窗口
2015/02/26 Javascript
jquery实现键盘左右翻页特效
2015/04/30 Javascript
nodejs个人博客开发第七步 后台登陆
2017/04/12 NodeJs
js学习总结之DOM2兼容处理重复问题的解决方法
2017/07/27 Javascript
vue实现长图垂直居上 vue实现短图垂直居中
2017/10/18 Javascript
layui table 多行删除(id获取)的方法
2019/09/12 Javascript
node.js express框架实现文件上传与下载功能实例详解
2019/10/15 Javascript
uni-app如何页面传参数的几种方法总结
2020/04/28 Javascript
vue proxy 的优势与使用场景实现
2020/06/15 Javascript
详细分析JavaScript中的深浅拷贝
2020/09/17 Javascript
通过实例解析js可枚举属性与不可枚举属性
2020/12/02 Javascript
[09:37]DOTA2卡尔工作室 英雄介绍圣堂刺客篇
2013/06/13 DOTA
[02:41]《西雅图我们来了》2015国际邀请赛出征全记录
2015/07/23 DOTA
提升Python程序运行效率的6个方法
2015/03/31 Python
Pycharm学习教程(2) 代码风格
2017/05/02 Python
Python2随机数列生成器简单实例
2017/09/04 Python
python机器学习之神经网络(二)
2017/12/20 Python
Python OpenCV处理图像之滤镜和图像运算
2018/07/10 Python
如何利用Boost.Python实现Python C/C++混合编程详解
2018/11/08 Python
Django model select的多种用法详解
2019/07/16 Python
Django后台管理系统的图文使用教学
2020/01/20 Python
使用openCV去除文字中乱入的线条实例
2020/06/02 Python
Keras中的两种模型:Sequential和Model用法
2020/06/27 Python
windows+vscode安装paddleOCR运行环境的步骤
2020/11/11 Python
Python实现简单猜数字游戏
2021/02/03 Python
纯CSS和jQuery实现的在页面顶部显示的进度条效果2例(仿手机浏览器进度条效果)
2014/04/16 HTML / CSS
HTML5中使用postMessage实现两个网页间传递数据
2016/06/22 HTML / CSS
美国精品家居用品网站:US-Mattress
2016/08/24 全球购物
美国珠宝精品店:Opulent Jewelers
2019/08/20 全球购物
学习党章思想汇报
2014/01/07 职场文书
规划编制实施方案
2014/03/15 职场文书
商务英语专业求职信
2014/06/26 职场文书
董事长助理岗位职责
2015/02/11 职场文书
小学毕业感言200字
2015/07/30 职场文书
2016简历自荐信优秀范文
2016/01/29 职场文书
解决pytorch-gpu 安装失败的记录
2021/05/24 Python