【发布时间】:2013-12-16 06:22:47
【问题描述】:
请帮助我。我正在运行一个简单的 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新手。
非常感谢……
【问题讨论】:
-
表示你访问的索引(位置)不存在。
-
我将用什么代码替换我现有的代码???谢谢
-
我不知道;你能提供一个small self-contained reproducible example 并编辑你的问题以包含它吗?
-
您应该尝试使用 print(rows) 和 print(rows[1]) 来查看您的数据是什么样的。它可以帮助您找到问题。
-
当我将 train_sizes=np.linspace(0.1, 1.0, 10) 更改为 train_sizes=10 时出现此错误
标签: python python-2.7 mysql-python