首页 > 编程语言 >python tkinter 使用(二)

python tkinter 使用(二)

时间:2023-12-26 20:24:53浏览次数:35  
标签:messagebox tkinter python button result 使用 print event def

python tkinter 使用(二)

本篇文章着重讲下tkinter中messagebox的使用。

1:提示框

def showinfo(event):
    messagebox.showinfo("这是个提示框","this is message content")

2:错误提示框

def showerror(event):
    messagebox.showerror("这是个错误提示框","this is message content")

3:警告提示框

def showwarning(event):
    messagebox.showwarning("这是个警告提示框","this is message content")

4:询问对话框

使用messagebox.askquestion方法 ,该方法的返回值是yes/no.

def askquestion(event):
    result = messagebox.askquestion("请听题:", "中国历史上第一个大一统的国家是秦朝吗?")
    print(result)
    if result == 'yes':
        print("回答正确")
    else:
        print("回答错误")

5:是/否对话框

askyesno的返回值是True/False

def askyesno(event):
    result = messagebox.askyesno("选择吧","这是个弹框吗?")
    print(result)
    if result:
        print("回答正确")
    else:
        print("回答错误")

6:重试取消对话框

askretrycancel 返回值是True/False

def askretrycancel(event):
    result = messagebox.askretrycancel("重试","确认选择?")
    print(result)

7:确认取消对话框

返回值是True/False

def askokcancel(event):
    result = messagebox.askokcancel("取消框","确认取消吗?")
    print(result)

8:是/否/取消 对话框

返回值是True/False/None

def askyesnocancel(event):
    result = messagebox.askyesnocancel("!!!","选择吧!")
    print(result)

最后附上代码:

#!/usr/bin/python3# -*- coding: UTF-8 -*-""" @Author: zh @Time 2023/11/21 下午8:08  . @Email: xxxx @Describe:"""import tkinter as tkfrom tkinter import messagebox# 创建窗口root = tk.Tk()root.title("root")root.geometry("500x500")def showinfo(event):    messagebox.showinfo("这是个提示框","this is message content")def showerror(event):    messagebox.showerror("这是个错误提示框","this is message content")def showwarning(event):    messagebox.showwarning("这是个警告提示框","this is message content")def askquestion(event):    result = messagebox.askquestion("请听题:", "中国历史上第一个大一统的国家是秦朝吗?")    print(result)    if result == 'yes':        print("回答正确")    else:        print("回答错误")def askyesno(event):    result = messagebox.askyesno("选择吧","这是个弹框吗?")    print(result)    if result:        print("回答正确")    else:        print("回答错误")def askretrycancel(event):    result = messagebox.askretrycancel("重试","确认选择?")    print(result)def askokcancel(event):    result = messagebox.askokcancel("取消框","确认取消吗?")    print(result)def askyesnocancel(event):    result = messagebox.askyesnocancel("!!!","选择吧!")    print(result)button = tk.Button(text= "提示框")button.pack()button.bind('<1>', showinfo)button = tk.Button(text= "错误提示框")button.pack()button.bind('<1>', showerror)button = tk.Button(text="警告提示框")button.pack()button.bind('<1>', showwarning)button = tk.Button(text="提问框")button.pack()button.bind('<1>', askquestion)button = tk.Button(text="确认弹框")button.pack()button.bind('<1>', askyesno)button = tk.Button(text="取消框")button.pack()button.bind('<1>', askokcancel)button = tk.Button(text="retry/取消框")button.pack()button.bind('<1>', askretrycancel)button = tk.Button(text="yes/no/cancel 框")button.pack()button.bind('<1>', askyesnocancel)root.mainloop()

标签:messagebox,tkinter,python,button,result,使用,print,event,def
From: https://www.cnblogs.com/zhjing/p/17929275.html

相关文章

  • python tkinter 使用(十)
    pythontkinter使用(十)#!/usr/bin/python3#-*-coding:UTF-8-*-"""@Author:zh@Time2023/11/27下午3:36.@Email:@Describe:"""importtkinterfromtkinterimport*master=Tk()master.title("菜单")master.ge......
  • python tkinter 使用(三)
    pythontkinter使用(三)本篇文章主要讲下tkinter下的filedialog的使用.1:askopenfilename首先使用tkinter中fiedialog来实现一个简单的文件选择器.这里使用askopenfilename()来启动文件选择器,选择成功后打印下所选文件的名称.#!/usr/bin/python3#-*-coding:UTF-8-*-......
  • python tkinter使用(五)
    pythontkinter使用(五)本篇文章讲述tkinter中treeview的使用Treeview是一个多列列表框,可以显示层次数据。#!/usr/bin/python3#-*-coding:UTF-8-*-"""@Author:zh@Time2023/11/23下午8:28.@Email:@Describe:treeview使用"""importtkinterastkfrom......
  • python tkinter使用(四)
    pythontkinter使用(四)本篇文章主要讲下tkinter的文本框相关.tkinter中用Entry来实现输入框,类似于android中的edittext.具体的用法如下:1:空白输入框如下:name=tk.Entry(window)name.pack()2:设置输入框的默认文案name=tk.Entry(window)name.pack()name.inser......
  • python tkinter使用(十一)
    pythontkinter使用(十一)本篇文章主要讲下tkinter窗口的一些属性,以及实现无法关闭的窗口中遇到的一些问题.#!/usr/bin/python3#-*-coding:UTF-8-*-"""@Author:zh@Time2023/11/28下午13:23.@Email:@Describe:"""fromtkinterimport*importtkinteras......
  • Android Notification 以及 通知铃音使用
    AndroidNotification以及通知铃音使用上一篇文章讲了手机震动的使用.本篇继续讲解铃音的使用,并且在讲下通知消息的使用.1:通知消息的使用代码如下:publicstaticvoidnotice(Contextcontext){try{NotificationCompat.Builderbuilder=ne......
  • python获取已安装程序列表
    python获取已安装程序列表本文主要讲述通过python脚本获取android设备已安装列表。首先,Python本身无法直接获取Android设备上已安装的程序列表,所以这里主要借助adb命令来实现。具体的内容如下:#!/usr/bin/python#coding=utf-8importsubprocessimportos#通过adb命令获取......
  • python+pytest接口自动化 —— 参数关联
    什么是参数关联?参数关联,也叫接口关联,即接口之间存在参数的联系或依赖。在完成某一功能业务时,有时需要按顺序请求多个接口,此时在某些接口之间可能会存在关联关系。比如:B接口的某个或某些请求参数是通过调用A接口获取的,即需要先请求A接口,从A接口的返回数据中拿到需要的字段值,在请......
  • [资源管理] SQL Server 通过Resouce Governor来限制用户资源的使用
    创建资源池CREATERESOURCEPOOL[rp_test]WITH(min_cpu_percent=0,max_cpu_percent=1,min_memory_percent=0,max_memory_percent=1,AFFINITYSCHEDULER=AUTO)GO创建负载组CREATEWORKLOADGROUP[wlp_test]WITH(group_max_requests=10,importance=High,request_m......
  • Python subprocess 使用(二)
    Pythonsubprocess使用(二)本篇继续介绍subprocess的使用.这里主要添加两个自己在工作过程中常用的两个小命令.1:获取顶层activityimportsubprocessdefget_top_activity():#使用adb命令获取顶层activitycmd='adbshelldumpsyswindow|grep"mCurrentFocu......