IndexError:元组索引超出范围----- Python

杰拉德·桑切斯(Jerald Sanchez):

请帮我。我正在运行一个简单的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中是新的。

非常感谢....

glglgl:

索引之一可能是错误的,要么是内部索引,要么是外部索引。

我怀疑你的意思是说[0],你说[1][1],你说[2]索引在Python中从0开始。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python:IndexError:元组索引超出范围

在Python中格式化字符串时出现“ IndexError:元组索引超出范围”

IndexError:列表索引超出范围-Python CSV

Python请求:“ IndexError:列表索引超出范围”

Python DJANGO错误IndexError在/列表索引超出范围

Python错误:“ IndexError:字符串索引超出范围”

IndexError:列表索引超出范围python 3.6

IndexError:列表分配索引超出范围,Python

Python 3.7.2:IndexError:列表索引超出范围

Python CSV:IndexError:列表索引超出范围

Python Web抓取“ IndexError:列表索引超出范围”

IndexError:通过使用Raspberry pi在Python中的元组索引超出范围

IndexError:列表索引超出范围(Python 2.7)

Python-IndexError:列表索引超出范围

python xpath IndexError:列表索引超出范围

IndexError:在python中列出索引超出范围

IndexError:列表索引超出范围错误python

Python 3:IndexError:列表索引超出范围

IndexError:Python 3中的列表索引超出范围

IndexError:列表索引超出范围 - Python 3.5.2

IndexError:在python列表中列出索引超出范围

获取IndexError:在python中列表分配索引超出范围

Python 3 - IndexError:字符串索引超出范围

Python 单元测试 - IndexError:列表索引超出范围

如何修复python中的“IndexError:元组索引超出范围”?

IndexError:列表索引超出范围(Python)

Python 网页抓取“IndexError:列表索引超出范围”

IndexError:列表索引超出范围python(烧瓶)

IndexError:使用python列出超出范围的索引