tkinter-消息框、对话框

ゝ一世哀愁。 2021-06-11 15:12 709阅读 0赞

一、导包

  1. from tkinter import \*
  2. from tkinter.messagebox import \*

二、消息框

  1. 1、提示消息框
  2. showinfo('提示','提示信息')
  3. ![70][]
  4. 2、警告消息框
  5. showwarning('警告','警告信息')
  6. ![70 1][]
  7. 3、错误消息框
  8. showerror('错误','错误信息')
  9. ![70 2][]

三、对话框

  1. 1askokcancel('提示', '要执行此操作吗')
  2. 询问操作是否进行;如果答案为OK,返回true
  3. ![70 3][]
  4. 2askquestion('提示', '这个答案对吗')
  5. 问一个问题;如果答案为是,返回yes
  6. ![70 4][]
  7. 3askyesno('提示', '这个答案对吗')
  8. 问一个问题;如果答案为是,返回true
  9. ![70 5][]
  10. 4askretrycancel('提示', '要重试此操作吗')
  11. 询问是否应重试操作;如果答案为是,则返回true
  12. ![70 6][]
  13. 5askyesnocancel('提示', '这个答案对吗')
  14. 问一个问题;如果答案为是,则返回true,点击取消,则返回none
  15. ![70 7][]

四、例子

from ctypes import *

from tkinter import *

from tkinter.messagebox import *

import tkinter.messagebox

root = tkinter.Tk()

root.withdraw() # 隐藏

d = askokcancel(‘提示’, ‘做我女朋友好不好’) # true false

if d == False:

  1. showinfo('提示', '好吃的都给你')

e = askquestion(‘提示’, ‘做我女朋友好不好’) # yes no

if e == ‘no’:

  1. showinfo('提示', '你说的都是对的')

f = askyesno(‘提示’, ‘做我女朋友好不好’) # true false

if f == False:

  1. showinfo('提示', '房产证写你名')

g = askretrycancel(‘提示’, ‘做我女朋友好不好’) # true false

if g == False:

  1. showinfo('提示', '保大')

h = askyesnocancel(‘提示’, ‘确定不做我女朋友吗’) # true false cancel

if h == True:

  1. showwarning('警告', '电脑即将关机')
  2. user32 = windll.LoadLibrary('user32.dll')
  3. user32.LockWorkStation()

mainloop()

发表评论

表情:
评论列表 (有 0 条评论,709人围观)

还没有评论,来说两句吧...

相关阅读