2013-02-20 66 views
0

基本上我寫了一個圖形用戶界面,使數學遊戲,並將其鏈接到我的microsft訪問數據庫使用sql,但我無法得到我的問題打印到我的標籤,任何想法?。另外,如何從我的問題列表中生成一個隨機數字,因爲您可以看到我的jim語句不起作用。麻煩顯示我的問題從我的數據庫

import Tkinter 
import Databaseconnector 


class simpleapp_tk(Tkinter.Tk): 
    def __init__(self,parent): 
     Tkinter.Tk.__init__(self,parent) 
     self.parent = parent 
     self.initialize() 

    def initialize(self): 
     jim = randomnumber() 

     SQL = 'SELECT * FROM tblQuestion' 
     cursor = Databaseconnector.SELECT(SQL) 
     rows = cursor.fectchall() 
     for row in rows: 
      print row.Question, row.Hint, row.A1, row.A2, row.A3, row.A4, row.CorrectAnswer 
      alabel2.set("Question: " + (row.question)(jim).Item(1)) 

    def create_widgets(self): 
     # create welcome label 
     label1 = Tkinter.Label(self, text = "Question Game !") 
     label1.grid(row = 0, column = 1, columnspan = 2, sticky = 'W') 

     # create intruction label 
     alabel2 = Tkinter.Label(self, text = "") 
     alabel2.grid(row = 1, column = 0, columnspan = 2, sticky = 'W') 

     a1loginbutton = Tkinter.Button(self, text = "Enter",) 
     a1loginbutton.grid(row = 9, column = 1, sticky = 'W') 

     label3 = Tkinter.Label(self, text = "") 
     label3.grid(row = 10, column = 0, columnspan = 2, sticky = 'W') 

     a2loginbutton = Tkinter.Button(self, text = "Enter",) 
     a2loginbutton.grid(row = 11, column = 1, sticky = 'W') 

     a3loginbutton = Tkinter.Button(self, text = "Enter",) 
     a3loginbutton.grid(row = 9, column = 3, sticky = 'E') 

     a4loginbutton = Tkinter.Button(self, text = "Enter",) 
     a4loginbutton.grid(row = 11, column = 3, sticky = 'E') 

     label4 = Tkinter.Label(self, text = "") 
     label4.grid(row = 12, column = 0, columnspan = 2, sticky = 'W') 

     hiloginbutton = Tkinter.Button(self, text = "Hint",) 
     hiloginbutton.grid(row = 13, column = 3, sticky = 'E') 

     label5 = Tkinter.Label(self, text = "Score:") 
     label5.grid(row = 14, column = 1, columnspan = 5, sticky = 's') 

     def close_page(self): 
      self.destroy() 

if __name__ == "__main__": 
    app = simpleapp_tk(None) 
    app.title('my application') 
    app.geometry("150x200") 
    app.mainloop() 

回答

0

編輯基於評論從OP:

  1. 沒有在這一行一個錯字:rows = cursor.fectchall()
  2. 嘗試改變label.set語句來一個簡單的例子,以確認其工作原理。 alabel2.set("Question: " + row.question)
  3. 什麼是randomnumber()函數,(row.question)(jim).Item(1)行應該返回什麼?
+0

據somethging我寫:DBFILE = 'E:\ COMPUTING課程\ OI OI \ FinallyWorking \工作\ Mathsvaders.accdb' 康恩= pyodbc.connect('DRIVER = {Microsoft Access驅動程序(* .MDB * .ACCDB)}; DBQ ='+ DBFILE) 光標= conn.cursor() #def DBCONNECT(): DEF SELECT(SQL): 打印(SQL) 返回cursor.execute(SQL) – 2013-02-20 10:26:08

+0

我改變了cursor.fetchall的東西,但它不讓我把它放在標籤中 – 2013-02-20 10:43:46