python实例代码 python中yes ok cancel对话框

发布时间:2020-09-29编辑:脚本学堂
本文分享下,python中yes、ok、cancel取消对话框的例子,有需要的朋友参考下吧。

python实例代码:显示Yes、OK、Cancel对话框的例子。

代码:

#!/bin/python
#edit by www.jb200.com

from Tkinter import *
from Dialog import Dialog

class OldDialogDemo(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        Pack.config(self)  # same as self.pack()
        Button(self, text='Pop1', command=self.dialog1).pack()
        Button(self, text='Pop2', command=self.dialog2).pack()
    def dialog1(self):
        ans = Dialog(self,
                     title   = 'Title!',
                     text    = 'text'
                               'and text "quotation".',
                     bitmap  = 'questhead',
                     default = 0, strings = ('Yes', 'No', 'Cancel'))
        if ans.num == 0: self.dialog2()
    def dialog2(self):
        Dialog(self, title   = 'title',
                     text    = "text",
                     bitmap  = 'hourglass',
                     default = 0, strings = ('spam', 'SPAM'))

if __name__ == '__main__': OldDialogDemo().mainloop()

效果图,如下:
python对话框