本文介绍了IndexError:元组索引超出范围----- Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助我.我正在运行一个简单的python程序,它将以tkinter格式显示来自mySQL数据库的数据...
Please Help me. I'm running a simple python program that will display the data from mySQL database in a tkinter form...
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的新手.
Can anyone help me??? im new in python.
非常感谢您....
推荐答案
其中一个索引可能是错误的,无论是内部索引还是外部索引.
Probably one of the indexes is wrong, either the inner one or the outer one.
我怀疑您是说[0]
表示[1]
,而[1]
表示[2]
.索引在Python中从0开始.
I suspect you mean to say [0]
where you say [1]
and [1]
where you say [2]
. Indexes are 0-based in Python.
这篇关于IndexError:元组索引超出范围----- Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!