[英]Calling another GUI from a file in python
Suppose I have one GUI with a simple code as follows It has a button on it and when this is clicked I want to have another GUI to pop-up and then call the function from it. 假设我有一个带有以下简单代码的GUI,它上面有一个按钮,当单击它时,我想弹出另一个GUI,然后从中调用函数。 The problem is that when I run the first file, the GUI of the other one automatically pop-up.
问题是,当我运行第一个文件时,另一个文件的GUI会自动弹出。 What should I do.
我该怎么办。
The code of the first
file is as follows 第
first
文件的代码如下
from tkinter import *
import another
root = Tk()
button1 = Button(root, text = "Call" , command = another.abc)
button1.pack()
root.mainloop()
The code of second file another.py
is as follows 第二个文件
another.py
的代码如下
from tkinter import *
root_Test2 = Tk()
root_Test2.geometry('450x450')
def abc():
print("that's working")
root_Test2.mainloop()
Please suggest the solution that help me to open the second window when the button on the first one is clicked 请提出一种解决方案,该解决方案可在单击第一个窗口的按钮时帮助我打开第二个窗口
According to @PM 2Ring, You can change your second file's code to this: 根据@PM 2Ring,您可以将第二个文件的代码更改为此:
from tkinter import *
if __name__ == '__main__':
root_Test2 = Tk()
root_Test2.geometry('450x450')
def abc():
print("that's working")
if __name__ == '__main__':
root_Test2.mainloop()
You can find further information about if __name__ == '__main__'
here 您可以在此处找到有关
if __name__ == '__main__'
更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.