重新导入TKINTER



我有一个使用TKINTER GUI的文件,然后导入另一个应该打开顶层的脚本。新脚本不识别顶层,但除非我还添加了"from tkinter import *"对它也一样。我想知道为什么我必须为此重新导入tkinter ?

主脚本:

from tkinter import *
root = Tk() # initialize tkinter
root.geometry('307x730')

def decode():
if cust_active or def_active:
print("Currently Obtaining Data - Stop Data Recording to Decode Files")
return
import decoder
return

decode_button=Button(root, text="Decode Data", command=decode).pack()
root.mainloop()

decoder.py:

decode = Toplevel()

正确。两个模块都需要导入tkinter,否则第二个模块将无法使用tkinter类。每个模块都必须有自己的导入。

最新更新