messagebox:tkinter的消息框、对话框

一、messagebox.showinfo(title='提示', message='错误')

 from tkinter import *
from tkinter import messagebox
root = Tk()# 初始化 width = 380
height = 300
# 获取屏幕尺寸以计算布局参数,使窗口居屏幕中央
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(alignstr)
frame = Frame(root)
frame.pack()
def hit_me():
messagebox.showinfo(title='提示', message='错误')
button = Button(frame, text='点我', command=hit_me)
button.pack()
mainloop()

效果:

二、tkinter.messagebox.showwarning(title,message)

from tkinter import *
from tkinter import messagebox
root = Tk()
width = 380
height = 300
# 获取屏幕尺寸以计算布局参数,使窗口居屏幕中央
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(alignstr)
frame = Frame(root)
frame.pack()
def hit_me():
# messagebox.showinfo(title='提示', message='错误')
messagebox.showwarning(title='提示', message='错误')
button = Button(frame, text='点我', command=hit_me)
button.pack()
mainloop()

效果:

三、tkinter.messagebox.showinfo(title,message)

from tkinter import *
from tkinter import messagebox
root = Tk()
width = 380
height = 300
# 获取屏幕尺寸以计算布局参数,使窗口居屏幕中央
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(alignstr)
frame = Frame(root)
frame.pack()
def hit_me():
# messagebox.showinfo(title='提示', message='错误')
# messagebox.showwarning(title='提示', message='错误')
messagebox.showerror(title='提示',message='错误')
button = Button(frame, text='点我', command=hit_me)
button.pack()
mainloop()

效果:

四、messagebox.askquestion(title='提示',message='错误') #resurn 'yes' or 'no'

from tkinter import *
from tkinter import messagebox
root = Tk()
width = 380
height = 300
# 获取屏幕尺寸以计算布局参数,使窗口居屏幕中央
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(alignstr)
frame = Frame(root)
frame.pack()
def hit_me():
# messagebox.showinfo(title='提示', message='错误')
# messagebox.showwarning(title='提示', message='错误')
# messagebox.showerror(title='提示',message='错误')
Q = messagebox.askquestion(title='提示',message='错误') #resurn 'yes' or 'no'
print(Q)
button = Button(frame, text='点我', command=hit_me)
button.pack()
mainloop()

效果:(说明:按下是或否会返回yes或no)

五、messagebox.askyesno(title='提示', message='错误') # resurn 'True' or 'False'

Q = messagebox.askyesno(title='提示', message='错误')  # resurn 'True' or 'False'

效果:(说明:按下是或否会返回True或False

六、messagebox.askretrycancel(title='提示', message='错误') # resurn 'True' or 'False'

Q = messagebox.askretrycancel(title='提示', message='错误')  # resurn 'True' or 'False'

效果:说明:按下是或否会返回True或False

七、messagebox.askokcancel(title='提示', message='错误') # resurn 'True' or 'False'

Q = messagebox.askokcancel(title='提示', message='错误')  # resurn 'True' or 'False'

效果:说明:按下是或否会返回True或False

Python之tkinter.messagebox弹窗的更多相关文章

  1. Python基于tkinter.messagebox实现简易消息框、对话框

    库导入: import tkinter import tkinter.messagebox 有关提示框: tkinter.messagebox.showinfo(title=None, message ...

  2. Python的tkinter和tkinter.messagebox应用-鼠标和键盘命令绑定

    __author__ = 'Administrator' from tkinter import * import tkinter.messagebox class MainWindow: def b ...

  3. python tkinter messagebox

    """messagebox消息框""" import tkinter as tk #导入messagebox import tkinter. ...

  4. Python GUI - tkinter

    目录: Tkinter 组件 标准属性 几何管理 代码实例: 1. Label & Button 2. Entry & Text 3.Listbox列表 4.Radiobutton单选 ...

  5. python界面Tkinter编程(tkMessageBox对话框使用)

    python界面Tkinter编程(tkMessageBox对话框使用)     转载 https://blog.csdn.net/m_buddy/article/details/80105154 1 ...

  6. python之tkinter学习目录

    前言 下面的目录结构,采用的学习视频资料是网易云课堂中[莫凡]老师的,在目录的最下面的地方给出了对应的链接! 学习是逐渐积累起来的,代码也是!下面的每一篇中的对应代码,都秉承着这样的一个理念:代码是成 ...

  7. 对类HelloWorld程序中添加一个MessageBox弹窗

    对类HelloWorld程序中添加一个MessageBox弹窗 分析: 任一程序运行的时候都会加载kernel32.dll的,但MessageBoxA()这个API却是在user32.dll中的.所以 ...

  8. Python GUI - Tkinter tkMessageBox

    Python GUI - Tkinter tkMessageBox: tkMessageBox模块用于显示在您的应用程序的消息框.此模块提供了一个功能,您可以用它来显示适当的消息     tkMess ...

  9. 【C#】使用user32.dll的MessageBox弹窗消息

    要使用user32.dll的MessageBox弹窗消息,自然需要引入user32.dll到项目中. 一个最简单的实例如下: using System; using System.Runtime.In ...

随机推荐

  1. 攻防世界(XCTF)WEB(进阶区)write up(四)

    ics-07  Web_php_include  Zhuanxv Web_python_template_injection ics-07 题前半部分是php弱类型 这段说当传入的id值浮点值不能为1 ...

  2. Kali升级2018&&2019

    0X01修改更新源 vim /etc/apt/sources.list #中科大 deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-f ...

  3. php 加入 unless 语法

    1. php 的版本 :PHP 7.3.0-dev (cli) (built: Mar 18 2018 00:28:55) ( NTS ) 2. unless 语法结构: unless($cond){ ...

  4. 如何巧妙地在基于 TCP Socket 的应用中实现用户注册功能?

    通常,在基于TCP的应用中(比如我开源的GGTalk即时通信系统),当TCP连接建立之后,第一个请求就是登录请求,只有登录成功以后,服务器才会允许客户端进行其它性质的业务请求.但是,注册用户这个功能比 ...

  5. Unity - HasExitTime用法

    本文详细分析了AnimatorController中动画切换过渡问题,即Translation过渡及hasExitTime的问题.方法为对实际项目中的所有情况进行分类,规划逻辑图,可视化分析解决这些问 ...

  6. Django中ORM的优化

    1. exists( ) 什么时候用 count( ) 和 len( )什么时候合适, 用values( )或values_list( )只取需要的列的数据 iterator()对数据对象生成迭代器, ...

  7. fenby C语言 P29

    野指针 malloc()分配内存: free()释放内存: p=(char*)malloc(100): #include <stdio.h>#include <stdlib.h> ...

  8. SpringBoot接管SpringMvc

    SpringBoot接管SpringMvc Spring Web MVC framework(通常简称为“Spring MVC”)是一个丰富的“model 视图控制器”web framework. S ...

  9. (Java) AES-128 数据加密

    package com.vcgeek.hephaestus.utils; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeyS ...

  10. TICK技术栈(二)Telegraf安装及使用

    1.什么是Telegraf? Telegraf是一个用Go语言开发的代理程序,可用于收集和报告指标.Telegraf插件直接从其运行的系统中获取各种指标,从第三方API中提取指标,甚至通过StatsD ...