0
我有一個代碼,它需要顯示數據庫中與輸入框中輸入的數據相同的值的標籤。但我只獲取顯示的標籤的最後一個值,而不是第一價值。只能從mysql中獲取最後一個值
數據庫:
a1 bike
a2 car
問題:如果我進入A1,自行車不displayed..but我得到的車進入A2時。
編碼:
import Tkinter as tki
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="mysql", # your password
db="sakila") # name of the data base
cursor = db.cursor()
# execute SQL select statement
cursor.execute("SELECT A1,A2 FROM adarsh1")
keywords1=[]
for i in cursor.fetchall():
keywords1.append(i[0])
keywords1.append(i[1])
class App(object):
def __init__(self,root):
self.root = root
self.txt_frm = tki.Frame(self.root, width=900, height=900)
self.txt_frm.pack(fill="both", expand=True)
button3 = tki.Button(self.txt_frm,text="CLICK 1", command = self.retrieve_inpu)
button3.grid(column=0,row=2)
self.entry = tki.Entry(self.txt_frm)
self.entry.grid(column=1,row=0)
#create label in init
self.label = tki.Label(self.txt_frm)
self.label.grid(column=0,row=3)
def retrieve_inpu(self):
ent = self.entry.get()
if ent in i[0]:
self.label['text'] = i[1]
root = tki.Tk()
app = App(root)
root.mainloop()