Tkinter 之MessageBox弹出框
一、参数说明
| 语法 | 作用 | 截图 |
|---|---|---|
| tk.messagebox.showwarning(title='提示', message='你确定要删除吗?') | 警告信息弹窗 | ![]() |
| tk.messagebox.showinfo('提示','你确定要删除吗?') | 提示信息弹窗 |
|
| tk.messagebox.showerror('提示','你确定要删除吗?') | 错误信息弹窗 |
|
| 语法 | 返回值 | 作用 |
|---|---|---|
| tk.messagebox.askokcancel('提示','要执行此操作吗') | True | False | (疑问)确定取消对话框 |
| tk.messagebox.askquestion('提示', '要执行此操作吗') | yes | no | (疑问)是否对话框 |
| tk.messagebox.askyesno('提示', '要执行此操作吗') | True | False | (疑问)是否对话框 |
| tk.messagebox.askretrycancel('提示', '要执行此操作吗') | True | False | (警告)重试取消对话框 |
| 语法 | 返回值 | 作用 |
|---|---|---|
| tk.filedialog.asksaveasfilename() | 含后缀文件目录 | 另存为窗口弹窗。 |
| tk.filedialog.asksaveasfile() | 文件流对象 | 另存为窗口弹窗,会创建文件。 |
| tkinter.filedialog.askopenfilename() | 含后缀文件目录 | 打开文件弹窗。 |
| tk.filedialog.askopenfile() | 文件流对象 | 打开文件弹窗, |
| tk.filedialog.askdirectory() | 目录名 | 选择文件弹窗 |
| tk.filedialog.askopenfilenames() | 元组 | 打开多个文件名 |
| tk.filedialog.askopenfiles()# | 列表 | 多个文件流对象 |
二、代码示例
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import tkinter as tkimport tkinter.messageboximport tkinter.filedialogwindow = tk.Tk()# 设置窗口大小winWidth = 600winHeight = 400# 获取屏幕分辨率screenWidth = window.winfo_screenwidth()screenHeight = window.winfo_screenheight()x = int((screenWidth - winWidth) / 2)y = int((screenHeight - winHeight) / 2)# 设置主窗口标题window.title("MessageBox参数说明")# 设置窗口初始位置在屏幕居中window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))# 设置窗口图标window.iconbitmap("./image/icon.ico")# 设置窗口宽高固定window.resizable(0, 0)tk.messagebox.askokcancel("提示", "你确定要删除吗?")tk.messagebox.askquestion("提示", "你确定要删除吗?")tk.messagebox.askyesno("提示", "你确定要删除吗?")tk.messagebox.askretrycancel("提示", "你确定要删除吗?")tk.messagebox.showinfo("提示", "你确定要删除吗?")tk.messagebox.showwarning("提示", "你确定要删除吗?")tk.messagebox.showerror("提示", "你确定要删除吗?")# tk.filedialog.asksaveasfilename()window.mainloop() |




浙公网安备 33010602011771号