"""messagebox消息框"""
import tkinter as tk
#导入messagebox
import tkinter.messagebox as messagebox
window = tk.Tk()
window.title("My Window")
window.geometry("400x400")
var = tk.StringVar()
var.set("Hello world")
label = tk.Label(window,textvariable=var,font=("斜体",15),width=20,height=2,bg="black",fg="green")
label.pack()
def hit_me():
global label #使用全局变量
messagebox.showinfo(title="info",message="提示")
messagebox.showwarning(title="warning",message="警告")
messagebox.showerror(title="error",message="错误")
"""return yes or no"""
question = messagebox.askquestion(title="question",message="问题")
if question == "yes":
var.set("you selection yes")
else:
var.set("you selection no")
"""return True or False"""
askyesno = messagebox.askyesno(title="yes or no",message="选择")
if askyesno == True:
var.set("You selection True")
else:
var.set("You selection False")
"""return True or False"""
askokcancel = messagebox.askokcancel(title="cancel",message="取消")
if askokcancel == True:
var.set("You selection cancel")
else:
var.set("You don't selection cancel")
"""return True False None"""
result = messagebox.askyesnocancel(title="continue",message="Hello World")
if result == True:
var.set("You selection yes")
elif result == False:
var.set("You selection no")
elif result == None:
var.set("You selection cancel")
"""return True False"""
try_cancel = messagebox.askretrycancel(title="try_cancel",message="Hello World")
if try_cancel == True:
var.set("You selection retry")
else:
var.set("You selection cancel")
button = tk.Button(window,text="hit_me",command=hit_me,fg="red",bg="green")
button.pack()
window.mainloop()


python tkinter messagebox的更多相关文章

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

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

  2. Python之tkinter.messagebox弹窗

    messagebox:tkinter的消息框.对话框 一.messagebox.showinfo(title='提示', message='错误') from tkinter import * fro ...

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

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

  4. 关不掉的小姐姐程序python tkinter实现 学习---打包教程

    首先,我们先准备两个.py文件,还要图片文件         代码//是我自己手写的,copy时记得删掉,不然有可能错误,比如中英文啥的    当然 一些语法的无问题就百度,都能给你答案 第一个.py ...

  5. Python Tkinter 学习成果:点歌软件music

    笔者工作业余时间也没什么爱好,社交圈子也小,主要娱乐就是背着自己带电瓶的卖唱音响到住地附近找个人多的位置唱唱KtV. 硬件上点歌就用笔记本电脑,歌曲都是网上下载的mkv格式的含有两个音轨的视频.因此点 ...

  6. Python Tkinter 学习历程 一

    一丶一个简单的程序 from tkinter import * #引入所有类#查看tk版本#tkinter._test() root = Tk(); #对这个类进行实例化 w1 = Label(roo ...

  7. python Tkinter之Button

    Button小部件是一个标准的Tkinter的部件,用于实现各种按钮.按钮可以包含文本或图像,您可以调用Python函数或方法用于每个按钮. Tkinter的按钮被按下时,会自动调用该函数或方法. 该 ...

  8. python tkinter module的用法

    tkinter windows下从python3.2版本之后是自动安装的. python3.3之后的引入方式: >>> import _tkinter>>> imp ...

  9. python gui tkinter快速入门教程 | python tkinter tutorial

    本文首发于个人博客https://kezunlin.me/post/d5c57f56/,欢迎阅读最新内容! python tkinter tutorial Guide main ui messageb ...

随机推荐

  1. 解决微信小程序Video 某些属性设置不起作用问题

    <video controls="{{false}}" autoplay="{{true}}"></video> 设置属性务必要使用{{ ...

  2. python---哈希算法实现

    # coding = utf-8 class Array: def __init__(self, size=32, init=None): self._size = size self._items ...

  3. matplotlib基本用法-【老鱼学matplotlib】

    本文介绍一下matplotlib的最基本用法. 这次我们要显示一个线性方程的直线. 首先要引入matplotlib库,一般是用plt这个简写的,我们就按照大多数人的惯例来进行命名: import ma ...

  4. flask + MySQL-python 创建 webapp 应用

    0 - python 用自带的 wgsi 也可以创建 web 服务1)建立 hello.py 内容如下 # hello.pydef application(environ, start_respons ...

  5. python 字符串常用操作

    字符串常用方法 capitalize() String.capitalize() 将字符串首字母变为大写 name = 'xiaoming' new_name = name.capitalize() ...

  6. open

    open服务指的是封装的订单流接口,给外部第三方提供使用.(当然也可以区别的名字,我司这么叫而已,并且是用Java写的,谁晓得为什么不选择PHP来写)通过open api合作方就可以通过调用接口直接下 ...

  7. Google代码规范

    文件名 文件名须全部小写,下划线(_)和短横线(-) 源文件采用 UTF-8 编码. 非空代码块:K&R 风格 左花括号不另起新行 左花括号后紧跟换行 右花括号前需要换行 如果右花括号结束了语 ...

  8. oracle 删除重复记录

    查询及删除重复记录的SQL语句   1.查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断   select * from 表 where Id in (select Id from 表 g ...

  9. Synergy简单使用小记

    需求: 两台笔记本用两套键盘鼠标,那体验,糟透了. 怎样才能使得两个主机公用一套鼠标和键盘呢?上网搜索到Synergy这款软件 参考: 具体使用方法参考了这篇博文 基本使用: 这款软件分为服务端和客户 ...

  10. Python中的__init__和__new__

    一.__init__ 方法是什么? 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__ 方法通常用在初始化一个类实例的时候.例如: # -*- c ...