0
votes

As part of my log in GUI, once the correct details are entered, the user goes through to the homescreen page.

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

However, when the Homescreenscroll - Copy3.1.py is opened and runs, it says

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

Even though it is clearly defined in the 'Homescreenscroll - Copy3.1.py' file

It is part of this thread in the 'Homescreenscroll - Copy3.1.py' file:

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"
2
your login function and try section look empty here, please fix the indentation.Elisha
I guessed Label it is a Tkinter object. please add this information. in addition, try to add the line global WTI in the beginning of trick functionElisha

2 Answers

0
votes

Define WTI.
Put some text in the definition, instead of nothing.

0
votes

I just needed to import the module. That seemed to have done it for me.

So, from the login GUI I have put:

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

The only issue now is that within that module is the thread called 'Trick' which is not running when called through the login way. It only works when I run the actual HomescreenscrollCopy31.py version itself!

HomescreenscrollCopy31.py looks likes this:

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"

When opened via the login screen, the shell only prints the "start up" and never the "Trick running"

Why is this?