写了段代码,想在按下button的时候跳个提示框出来,调试的时候提示了messagebox未定义
from tkinter import * def test_show(): messagebox.showinfo(None, 'first') root = Tk() one = Label(root, text = 'First') one.pack() two = Button(root, text = 'First', command=test_show) two.pack() mainloop()
而后在CSDN上看到有人说messagebox输入子模块,不会默认导入,然后在开头加入了messagebox的导入,程序就可以正常执行了
from tkinter import * from tkinter import messagebox def test_show(): messagebox.showinfo(None, 'first') root = Tk() one = Label(root, text = 'First') one.pack() two = Button(root, text = 'First', command=test_show) two.pack() mainloop()