在 Python 中使用消息框时出现错误
I get an error when using messagebox in Python
我是 Python 的初学者,不会使用它 messagebox
这是我的代码
from tkinter import *
window=Tk()
def clicked():
global label
global txt
label ["text"]=txt.get()
print(label.cget("text"))
messagebox.showinfo("Title","hello frind!")
window.title("This is My Window")
window.geometry("500x400")
label=Label(window,text=" Window1 ")
label.grid(column=1, row=0)
txt=Entry(window,width=15)
txt.grid(column=2,row=0)
bt=Button(window,text="Click",command=clicked)
bt.grid(column=4,row=0)
window.mainloop()
这一行的错误
messagebox.showinfo("Title","hello frind!")
IndentationError: unindent 不匹配任何外部缩进级别
添加
“从 tkinter 导入消息框”
你的代码有效fine.You只需要从 tkinter 导入消息框
from tkinter import *
from tkinter import messagebox
window=Tk()
def clicked():
global label
global txt
label ["text"]=txt.get()
print(label.cget("text"))
messagebox.showinfo("Title","hello frind!")
window.title("This is My Window")
window.geometry("500x400")
label=Label(window,text=" Window1 ")
label.grid(column=1, row=0)
txt=Entry(window,width=15)
txt.grid(column=2,row=0)
bt=Button(window,text="Click",command=clicked)
bt.grid(column=4,row=0)
window.mainloop()
我是 Python 的初学者,不会使用它 messagebox
这是我的代码
from tkinter import *
window=Tk()
def clicked():
global label
global txt
label ["text"]=txt.get()
print(label.cget("text"))
messagebox.showinfo("Title","hello frind!")
window.title("This is My Window")
window.geometry("500x400")
label=Label(window,text=" Window1 ")
label.grid(column=1, row=0)
txt=Entry(window,width=15)
txt.grid(column=2,row=0)
bt=Button(window,text="Click",command=clicked)
bt.grid(column=4,row=0)
window.mainloop()
这一行的错误
messagebox.showinfo("Title","hello frind!")
IndentationError: unindent 不匹配任何外部缩进级别
添加
“从 tkinter 导入消息框”
你的代码有效fine.You只需要从 tkinter 导入消息框
from tkinter import *
from tkinter import messagebox
window=Tk()
def clicked():
global label
global txt
label ["text"]=txt.get()
print(label.cget("text"))
messagebox.showinfo("Title","hello frind!")
window.title("This is My Window")
window.geometry("500x400")
label=Label(window,text=" Window1 ")
label.grid(column=1, row=0)
txt=Entry(window,width=15)
txt.grid(column=2,row=0)
bt=Button(window,text="Click",command=clicked)
bt.grid(column=4,row=0)
window.mainloop()