我对制作 GUI 很陌生。我在 IDLE (2.7.3) 中工作,想用一个按钮打开一个简单的窗口。这是我的代码:
from Tkinter import *
import sys
win=Tk()
button1=Button(win, text = "ok", command = sys.exit, foreground = "red")
button1.pack()
mainloop()
如果我不使用mainloop()
,窗口将不会打开。如果我确实使用mainloop()
了,当我单击“确定”按钮时会出现此错误,并且带有该按钮的窗口不会关闭:
Traceback (most recent call last):
File "C:\Python27\GUI.py", line 6, in <module>
mainloop()
File "C:\Python27\lib\lib-tk\Tkinter.py", line 325, in mainloop
_default_root.tk.mainloop(n)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1412, in __call__
raise SystemExit, msg