n在那里时没有定义'N'

时间:2018-05-08 09:23:10

标签: python-3.x

我对 r.destroy 函数有问题,它说它没有定义但是它在那里

"Project.py", line 9, in RandomG
    r.destroy()
NameError: name 'r' is not defined

  from tkinter import *
    import xlrd
    import random
    import os

    def RandomG():
        r.destroy()
        rootA.destroy()
        r2 = Tk()
        r2.title('Random Generator')
        r2.geometry('400x300')
        r2.mainloop

    def Login():
        global nameEL
        global pwordEL # More globals :D
        global rootA

        rootA = Tk() # This now makes a new window.
        rootA.title('Login') # This makes the window title 'login'
        rootA.geometry('200x100')
        rootA.resizable(False, False)
        rootA.mainloop()


    def CheckLogin():
        with open(creds) as f:
            data = f.readlines() 
            uname = data[1].rstrip() 
            pword = data[3].rstrip() 

        if nameEL.get() == uname and pwordEL.get() == pword: 
            r = Tk() # Opens new window
            r.title(':D')
            r.resizable(False, False)
            r.geometry('150x50')
            rlbl = Label(r, text='Welcome ' + uname + '!')
            rlbl.grid(column=1, sticky=W)
            rg = Button(r, text='Continue', command=RandomG)
            rg.grid(columnspan=2, sticky=W)
            r.mainloop()


        else:
            r = Tk()
            r.title('D:')
            r.geometry('150x50')
            rlbl = Label(r, text='\n[!] Invalid Login')
            rlbl.pack()
            r.mainloop()

我正在使用python 3.6 32bit

0 个答案:

没有答案