Python 3.x tkinter按钮无法打开新窗口
我的tkinter有问题。 我的代码是要打开一个新的窗口按钮按下,但窗口不打开 这是我的密码: 主模块Python 3.x tkinter按钮无法打开新窗口,python-3.x,tkinter,window,Python 3.x,Tkinter,Window,我的tkinter有问题。 我的代码是要打开一个新的窗口按钮按下,但窗口不打开 这是我的密码: 主模块 #!/usr/bin/python #encoding: latin-1 import tkinter import ce #window config window = tkinter.Tk() #create window window.title("BBDOassist") #set title window.geometr
#!/usr/bin/python
#encoding: latin-1
import tkinter
import ce
#window config
window = tkinter.Tk() #create window
window.title("BBDOassist") #set title
window.geometry("750x500") #set size
…
# buttons
button_ce = tkinter.Button(window, text="CE Evaluation", command="ce.run()")
button_ce.pack()
window.mainloop() #draw the window and start
#!/usr/bin/python
#encoding: latin-1
import tkinter
…
def run():
#window config
window = tkinter.Tk() #create window
window.title("BBDOassist - CE Evaluation") #set title
window.geometry("750x500") #set size
…
window.mainloop() #draw the window and start
“CE”模块
#!/usr/bin/python
#encoding: latin-1
import tkinter
import ce
#window config
window = tkinter.Tk() #create window
window.title("BBDOassist") #set title
window.geometry("750x500") #set size
…
# buttons
button_ce = tkinter.Button(window, text="CE Evaluation", command="ce.run()")
button_ce.pack()
window.mainloop() #draw the window and start
#!/usr/bin/python
#encoding: latin-1
import tkinter
…
def run():
#window config
window = tkinter.Tk() #create window
window.title("BBDOassist - CE Evaluation") #set title
window.geometry("750x500") #set size
…
window.mainloop() #draw the window and start
你至少有两个问题 首先,必须为
命令
属性提供对函数的引用。你在传递一个字符串。一根绳子是无用的。您需要将按钮定义更改为:
button_ce = tkinter.Button(window, text="CE Evaluation", command=ce.run)
其次,如果要创建其他窗口,则需要创建Toplevel
的实例,而不是Tk
。tkinter程序只需要一个Tk
实例,您需要调用mainloop
一次
将run
更改为如下所示(并在run
中删除对mainloop
的调用):