【发布时间】:2021-09-27 16:51:59
【问题描述】:
我无法循环代码,这是我的代码,我希望让我的代码能够在按下按钮时加载另一个 py 模块,但是当我第二次循环时,即使缓存没有写入,它也会结束。
这是我使用的两个 .py 文件:
#test.py
import tkinter
import sys
sys.dont_write_bytecode = True
top = tkinter.Tk()
def next():
top.destroy()
import test2
B = tkinter.Button(top, text ="Hello", command = next)
B.pack()
top.mainloop()
#test2.py
import tkinter
import sys
sys.dont_write_bytecode = True
top = tkinter.Tk()
def next1():
top.destroy()
import test
B = tkinter.Button(top, text ="Hello", command = next1)
B.pack()
top.mainloop()
【问题讨论】:
-
import test将只导入一次test模块,相同语句的后续调用不会再次导入test模块。同样适用于import test2 -
您好,感谢您的澄清,请问有没有其他方法可以得到我想要的结果?
标签: python loops tkinter import destroy