释放双眼,带上耳机,听听看~!
from tkinter import *
from tkinter.messagebox import showinfo
def reply(name):
showinfo(title='Reply',message='Hello %s!' %name)
top = Tk()
top.title('Echo')
#top.iconbitmap('py-blue-trans-out.ico')
Label(top,text="Enter you name:").pack(side=TOP)
ent = Entry(top)
ent.pack(side=TOP)
btn = Button(top,text="Submit",command=(lambda: reply(ent.get())))
btn.pack(side=LEFT)
top.mainloop()

PS E:\py-program\ppe4> python tkinter103.py
Traceback (most recent call last):
File "tkinter103.py", line 9, in <module>
top.iconbitmap('py-blue-trans-out.ico')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1871, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "py-blue-trans-out.ico" not defined
from tkinter import *
from tkinter.messagebox import showinfo
def reply(name):
showinfo(title='Reply', message='Hello %s!' % name)
top = Tk()
#img = PhotoImage(file='py-blue-trans-out.ico') #no
top.title('Echo')
top.iconbitmap('@tool.xbm') #yes
#top.iconphoto(True, PhotoImage(file='tool.xbm')) #no
Label(top, text="Enter your name:").pack(side=TOP)
ent = Entry(top)
ent.pack(side=TOP)
btn = Button(top, text="Submit", command=(lambda: reply(ent.get())))
btn.pack(side=LEFT)
top.mainloop()