54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
From: john.michelsen at gte.net (John Michelsen)
|
|
Date: Tue, 20 Apr 1999 00:49:16 GMT
|
|
Subject: accessing calling scripts from called scripts at run time
|
|
Message-ID: <gaQS2.5877$s_5.291559@dfiatx1-snr1>
|
|
X-UID: 1151
|
|
|
|
I'm having trouble accessing a calling script from a called script at run
|
|
time.
|
|
Here is an example:
|
|
|
|
#first file, will call second
|
|
from Tkinter import *
|
|
import tkFileDialog, string
|
|
|
|
root = None
|
|
|
|
def importScript():
|
|
filename = tkFileDialog.askopenfilename()
|
|
if filename != '':
|
|
list = string.split(filename, '/')
|
|
filename = list[-1]
|
|
#dir = string.join(list[:-1], '/')
|
|
#sys.path.append(dir)
|
|
exec "import %s" % filename[:-3]
|
|
|
|
if __name__ == "__main__": #?
|
|
root = Tk()
|
|
b = Button(root, text="import script", command=importScript)
|
|
b.pack()
|
|
root.mainloop()
|
|
|
|
|
|
#another file, picked by tkFileDialog at run time by user
|
|
from importTest import root
|
|
root.config(bg='green')
|
|
|
|
|
|
If I put the "if __name__ == '__main__':" in, the second file can't get at
|
|
the
|
|
root properly. If I leave it out, when I import root in the second file, it
|
|
creates
|
|
a new root window. How can I get at the root without making a new one?
|
|
|
|
Thanks,
|
|
|
|
John
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|