请帮我。我正在运行一个简单的python程序,它将以tkinter形式显示来自mySQL数据库的数据...
from Tkinter import *
import MySQLdb
def button_click():
root.destroy()
root = Tk()
root.geometry("600x500+10+10")
root.title("Ariba")
myContainer = Frame(root)
myContainer.pack(side=TOP, expand=YES, fill=BOTH)
db = MySQLdb.connect ("localhost","root","","chocoholics")
s = "Select * from member"
cursor = db.cursor()
cursor.execute(s)
rows = cursor.fetchall()
x = rows[1][1] + " " + rows[1][2]
myLabel1 = Label(myContainer, text = x)
y = rows[2][1] + " " + rows[2][2]
myLabel2 = Label(myContainer, text = y)
btn = Button(myContainer, text = "Quit", command=button_click, height=1, width=6)
myLabel1.pack(side=TOP, expand=NO, fill=BOTH)
myLabel2.pack(side=TOP, expand=NO, fill=BOTH)
btn.pack(side=TOP, expand=YES, fill=NONE)
那就是整个程序。
错误是
x = rows[1][1] + " " + rows[1][2]
IndexError: tuple index out of range
y = rows[2][1] + " " + rows[2][2]
IndexError: tuple index out of range
谁能帮我???我在python中是新的。
非常感谢....
索引之一可能是错误的,要么是内部索引,要么是外部索引。
我怀疑你的意思是说[0]
,你说[1]
和[1]
,你说[2]
。索引在Python中从0开始。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句