tkinter之对话框
对话框的一个例子:

from tkinter.dialog import * from tkinter import * def investigation(): d=Dialog(None,title='快乐指数',text='2018年的您觉得过的快乐吗?', bitmap=DIALOG_ICON,default=0,strings=('不快乐','还可以','很快乐','非常快乐')) print(d.num) t=Button(None,text='幸福度调查',command=investigation) t.pack() b=Button(None,text='关闭',command=t.quit) b.pack() t.mainloop()
弹出一个消息提示框的例子:

from tkinter import * from tkinter.messagebox import * root=Tk() def s(): showinfo(title='hello',message='世界你好') b1=Button(root,text='open',command=s) b1.pack() root.mainloop()
关于顶层窗口:

from tkinter import * root=Tk() root.title('我是root窗口!') L=Label(root,text='我属于root') L.pack() f=Toplevel(root,width=30,height=20) f.title('我是toplevel') Lf=Label(f,text='我是toplevel') Lf.pack() root.mainloop()
复选框的例子:

from tkinter import * time1=0 time2=0 def xin1(): global t,c1,time1 if time1%2==0: time1+=1 t['text']='西瓜被选中' else: time1+=1 t['text']='西瓜被取消' def xin2(): global t,c2,time2 if time2%2==0: time2+=1 t['text']='芒果被选中' else: time2+=1 t['text']='芒果被取消' root=Tk() c1=Checkbutton(root,text='西瓜',command=xin1) c1.pack() c2=Checkbutton(root,text='芒果',command=xin2) c2.pack() t=Label(root,text='') t.pack() root.mainloop()
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步