2014-08-31 192 views
0

作爲我登錄GUI的一部分,一旦輸入了正確的詳細信息,用戶就會進入主屏幕頁面。NameError:全局名稱'WTI'未定義

def login(): 
    content = nameentry.get() 
    content1 = IDentry.get() 
    if content == "1" and content1 == "1": 
     root.destroy(), execfile("Homescreenscroll - Copy3.1.py") 

然而,當Homescreenscroll - Copy3.1.py打開並運行時,它說

Exception in thread Thread-1: Traceback (most recent call last):

File "C:\Users\Isaac\Desktop\Py\lib\threading.py", line 530, in __bootstrap_inner

self.run()

File "C:\Users\Isaac\Desktop\Py\lib\threading.py", line 483, in run

self.__target(*self.__args, **self.__kwargs)

File "Homescreenscroll - Copy3.1.py", line 5862, in trick

WTI['text'] = row[0] 

NameError: global name 'WTI' is not defined

即使它是在明確規定 'Homescreenscroll - Copy3.1.py' 文件

它是在 'Homescreenscroll - Copy3.1.py' 這個線程的部分文件:

WTI = Label(text = "") 

def trick(threadName, sleepTime): 
    while 1 < 2: 
    db=MySQLdb.connect(host = "xxx", 
        user = "xxx", 
        passwd = "xxx", 
        db = "test") 
    cursor = db.cursor() 
    cursor.execute("""xxxx""", (xxxxx)) 
    cursor.execute("""xxxx""", (xxxx)) 
    db.commit() 
    row=cursor.fetchone() 
    WTI['text'] = row[0] 


try: 
    t = threading.Thread(target=trick, args=("Trick running", 5)) 
    t.daemon = True 
    t.start() 
except: Exception, 
print "start up" 
+0

您的'登錄'功能和'嘗試'部分在這裏看起來是空的,請修復縮進。 – Elisha 2014-08-31 10:50:26

+0

我猜'標籤'它是一個'Tkinter'對象。請添加此信息。此外,嘗試在'trick'函數的開頭添加行'global WTI' – Elisha 2014-09-02 13:52:06

回答

0

的Defi ne WTI。
在定義中放置一些文本,而不是任何東西。

+0

它最初意味着打開空白,然後函數'trick'將其填入。 – 2014-09-02 14:20:52

+0

row [0]從哪裏來? – DarinL 2014-09-02 14:29:42

+0

row [0]來自cursor.execute,row = cursor.fetchone() – 2014-09-02 14:40:58

0

我只需要導入模塊。這似乎爲我做了。

所以,從登錄界面我已經把:

def login(): 
content = nameentry.get() 
content1 = IDentry.get() 
if content == "1" and content1 == "1": 
    root.destroy() 
    from HomescreenscrollCopy31 import FullScreenApp 

唯一的問題現在是該模塊中的一個名爲「天雷」通過登錄方式調用時未運行的線程。它只在我運行實際的HomescreenscrollCopy31.py版本本身時才起作用!

HomescreenscrollCopy31.py看起來喜歡這樣的:

class FullScreenApp(object): 
    def __init__(self, master, **kwargs): 
     self.master=master 
     pad=3 
     self._geom='200x200+0+0' 
     master.geometry("{0}x{1}+0+0".format(
      master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad)) 
     master.bind('<Escape>',self.toggle_geom)    
    def toggle_geom(self,event): 
     geom=self.master.winfo_geometry() 
     print(geom,self._geom) 
     self.master.geometry(self._geom) 
     self._geom=geom 

    def trick(threadName, sleepTime): 
     while 1 < 2: 
      .... 
    try: 
     t = threading.Thread(target=trick, args=("Trick running", 5)) 
     t.daemon = True 
     t.start() 
    except: Exception, 
    print "start up" 

當通過登錄屏幕打開,外殼只打印「啓動」,也不會「招運行」

這是爲什麼?

相關問題