怎么在Python3.7中使用tkinter實(shí)現(xiàn)查詢界面功能-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)怎么在Python3.7中使用tkinter實(shí)現(xiàn)查詢界面功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)龍游免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

Tkinter 是 Python 的標(biāo)準(zhǔn) GUI 庫(kù)。Python 使用 Tkinter 可以快速的創(chuàng)建 GUI 應(yīng)用程序。

#!/usr/bin/python
# -*- coding: UTF-8 -*-
from tkinter import *
import sqlite3
# 導(dǎo)入消息對(duì)話框子模塊
import tkinter.messagebox
#import urllib
 #創(chuàng)建主窗口
root = Tk()
root.title('球員查詢')
# 設(shè)置窗口大小
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)  #國(guó)籍
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)  #出場(chǎng)數(shù)
le_birthday = Label(root, textvariable = birthday).place(x = 100, y = 320)  #生日
le_habit = Label(root, textvariable = habit).place(x = 100, y = 350)  #慣用腳
#查詢按鈕響應(yīng)函數(shù)
def select(root, label):
 sname = label.get()
 print('input: ',sname)
 #查詢剛才插入的數(shù)據(jù)
 #由于剛才已經(jīng)關(guān)閉了數(shù)據(jù)庫(kù)連接,需要重新創(chuàng)建Connection對(duì)象和Cursor對(duì)象
 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+'球員不存在,請(qǐng)輸入其他球員姓名!') 
 else:
 print('result_name: ', list_re[0][0])
 #數(shù)據(jù)成功提取出來了
 #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])  #國(guó)籍
 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])  #出場(chǎng)數(shù)
 birthday.set(list_re[0][8])  #生日
 habit.set(list_re[0][9])  #慣用腳
 conn.close()
#定義一個(gè)返回按鈕調(diào)用的返回函數(shù):callback
def exit_program():
 quit()
def main():
 input_name = Label(root, text = '請(qǐng)輸入球員姓名:').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項(xiàng),可以指定點(diǎn)擊button時(shí)調(diào)用的callback函數(shù)
 #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 = '國(guó) 籍:').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 = '號(hào) 碼:').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()
Python的優(yōu)點(diǎn)有哪些

1、簡(jiǎn)單易用,與C/C++、Java、C# 等傳統(tǒng)語言相比,Python對(duì)代碼格式的要求沒有那么嚴(yán)格;2、Python屬于開源的,所有人都可以看到源代碼,并且可以被移植在許多平臺(tái)上使用;3、Python面向?qū)ο?,能夠支持面向過程編程,也支持面向?qū)ο缶幊蹋?、Python是一種解釋性語言,Python寫的程序不需要編譯成二進(jìn)制代碼,可以直接從源代碼運(yùn)行程序;5、Python功能強(qiáng)大,擁有的模塊眾多,基本能夠?qū)崿F(xiàn)所有的常見功能。

關(guān)于怎么在Python3.7中使用tkinter實(shí)現(xiàn)查詢界面功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

網(wǎng)站題目:怎么在Python3.7中使用tkinter實(shí)現(xiàn)查詢界面功能-創(chuàng)新互聯(lián)
瀏覽地址:http://bm7419.com/article8/dihdop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、App設(shè)計(jì)、定制開發(fā)、微信公眾號(hào)服務(wù)器托管、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)