Tkinter新窗口声明



最近在使用python时tkinters声明不起作用。我的意思是,对于以前没有导入tkinter的任何文件,创建窗口等简单代码都是不可能的。其他人遇到过这个问题吗?如果是,如何解决?如有任何反馈,我们将不胜感激。谢谢该代码只是用来在tkinter中打开一个窗口。但是,运行时不会显示任何窗口。

from tkinter import *
def sample():
window = Tk()
sample()

这太有趣了。

你必须使用tkinter。Tk((而不是Tk(((。

感谢

试试这个:

from tkinter import *  # Importing everything from the Tkinter module
win = Tk()  # Initializing Tkinter and making a window
def sample():
new_win = Toplevel()  # This creates a new window
sample()
win.mainloop()  # If this is not there, the code won't work

最新更新