Skip to content

Instantly share code, notes, and snippets.

@ladyrick
Last active November 22, 2018 02:40
Show Gist options
  • Save ladyrick/24b74ce75f624560bd8c8e5348b6259c to your computer and use it in GitHub Desktop.
Save ladyrick/24b74ce75f624560bd8c8e5348b6259c to your computer and use it in GitHub Desktop.
python的message box
class PyMsgBox():
def __init__(self):
from tkinter import Tk, messagebox
self.msgbox = messagebox
self.root = Tk()
self.root.wm_attributes('-topmost', 1)
self.root.withdraw()
def info(self, msg):
self.msgbox.showinfo("来自ladyrick的提示", msg)
def warning(self, msg):
self.msgbox.showwarning("来自ladyrick的警告", msg)
def error(self, msg):
self.msgbox.showerror("来自ladyrick的报错", msg)
def ask(self, msg):
return self.msgbox.askokcancel("来自ladyrick的询问", msg)
mytk = PyMsgBox()
mytk.info("萌高傻了……")
mytk.warning("萌高傻了。")
mytk.error("萌高傻了!")
if mytk.ask("萌高傻了?"):
print("萌高真的傻了。")
else:
print("萌高不傻。")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment