반응형
제발 도와주세요. mySQL 데이터베이스의 데이터를 tkinter 형식으로 표시하는 간단한 파이썬 프로그램을 실행 중입니다.
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
누구든지 나를 도울 수 있습니까 ??? 파이썬의 새로운 메신저.
정말 고맙습니다....
해결 방법
아마도 인덱스 중 하나가 안쪽이든 바깥 쪽이든 잘못되었을 것입니다.
[1]
에서 [0]
, [2] <에서
[1]
이라고 말하려는 것 같습니다. / code>. 인덱스는 Python에서 0부터 시작합니다.
참조 페이지 https://stackoverflow.com/questions/20296188
반응형
'파이썬' 카테고리의 다른 글
파이썬 파싱에서 요청 URL을 가져옵니다. (0) | 2020.12.31 |
---|---|
파이썬 Mac OS X에서 Python 3 용 pip를 설치하는 방법은 무엇입니까? (0) | 2020.12.30 |
파이썬 Pandas 데이터 프레임에서 열 수를 검색하려면 어떻게해야합니까? (0) | 2020.12.30 |
파이썬 Django Rest 프레임 워크 ImageField (0) | 2020.12.30 |
파이썬에서 공백으로 문자열을 고정 길이로 채우는 방법은 무엇입니까? (0) | 2020.12.30 |
댓글