随笔 - 1759  文章 - 0  评论 - 109  阅读 - 429万

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()
View Code
复制代码

弹出一个消息提示框的例子:

复制代码
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()
View Code
复制代码

关于顶层窗口:

复制代码
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()
View Code
复制代码

 

复选框的例子:

复制代码
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()
View Code
复制代码
posted on   一杯明月  阅读(717)  评论(0编辑  收藏  举报
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示