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 sort、sorted高级排序技巧
Nov 21 Python
Python实现的微信公众号群发图片与文本消息功能实例详解
Jun 30 Python
通过python+selenium3实现浏览器刷简书文章阅读量
Dec 26 Python
解决Python中list里的中文输出到html模板里的问题
Dec 17 Python
python-opencv 将连续图片写成视频格式的方法
Jan 08 Python
Spark处理数据排序问题如何避免OOM
May 21 Python
最新PyCharm从安装到PyCharm永久激活再到PyCharm官方中文汉化详细教程
Nov 17 Python
Python利用myqr库创建自己的二维码
Nov 24 Python
python实现企业微信定时发送文本消息的示例代码
Nov 24 Python
Python常用断言函数实例汇总
Nov 30 Python
Python中threading库实现线程锁与释放锁
May 17 Python
Python first-order-model实现让照片动起来
Jun 25 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
dede3.1分页文字采集过滤规则详说(图文教程)续二
2007/04/03 PHP
解决PHP超大文件下载,断点续传下载的方法详解
2013/06/06 PHP
Laravel学习教程之从入口到输出过程详解
2017/08/27 PHP
如何制作浮动广告 JavaScript制作浮动广告代码
2012/12/30 Javascript
Jquery判断$(&quot;#id&quot;)获取的对象是否存在的方法
2013/09/25 Javascript
详解Document.Cookie
2015/12/25 Javascript
jQuery实现对无序列表的排序功能(附demo源码下载)
2016/06/25 Javascript
jQuery+HTML5+CSS3制作支持响应式布局时间轴插件
2016/08/10 Javascript
jQuery判断是否存在滚动条的简单方法
2016/09/17 Javascript
Javascript数组中push方法用法分析
2016/10/31 Javascript
boostrapTable的refresh和refreshOptions区别浅析
2017/01/22 Javascript
canvas实现粒子时钟效果
2017/02/06 Javascript
Vue结合SignalR实现前后端实时消息同步
2017/09/19 Javascript
Vue完整项目构建(进阶篇)
2018/02/10 Javascript
MVVM 双向绑定的实现代码
2018/06/21 Javascript
jQuery实现带3D切割效果的轮播图功能示例【附源码下载】
2019/04/04 jQuery
详解Vue、element-ui、axios实现省市区三级联动
2019/05/07 Javascript
React Native 混合开发多入口加载方式详解
2019/09/23 Javascript
node.js express捕获全局异常的三种方法实例分析
2019/12/27 Javascript
[00:32]2018DOTA2亚洲邀请赛EG出场
2018/04/03 DOTA
[57:37]EG vs Mineski 2018国际邀请赛小组赛BO2 第二场 8.16
2018/08/17 DOTA
[00:06]Yes,it worked!小卡尔成功穿越时空加入战场!
2019/07/20 DOTA
python进程类subprocess的一些操作方法例子
2014/11/22 Python
KMP算法精解及其Python版的代码示例
2016/06/01 Python
Python实现的朴素贝叶斯算法经典示例【测试可用】
2018/06/13 Python
Python中创建二维数组
2018/10/17 Python
django echarts饼图数据动态加载的实例
2019/08/12 Python
python隐藏类中属性的3种实现方法
2019/12/19 Python
Django用内置方法实现简单搜索功能的方法
2020/12/18 Python
canvas绘制文本内容自动换行的实现代码
2019/01/14 HTML / CSS
泰国第一在线超市:Tops
2021/02/13 全球购物
中英文自我评价语句
2013/12/20 职场文书
电子专业自荐信
2014/07/01 职场文书
授权委托书公证
2014/09/14 职场文书
文员转正自我鉴定怎么写
2014/09/29 职场文书
跟班学习心得体会(共6篇)
2016/01/23 职场文书