-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom_messageboxes.py
96 lines (66 loc) · 3.1 KB
/
custom_messageboxes.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import tkinter as tk
from tkinter import ttk
import winsound
class CustomMessageBoxes(tk.Toplevel):
def __init__(self, parent, title, message):
super().__init__(parent)
self.title(title)
self.message = message
self.display_width = parent.winfo_screenwidth()
self.display_height = parent.winfo_screenheight()
self.left = int(self.display_width / 2 - (300 / 2))
self.top = int(self.display_height / 2 - (150 / 2))
self.geometry(f"300x150+{self.left}+{self.top}")
self.resizable(False, False)
self.transient(parent)
self.grab_set()
class CustomShowError(CustomMessageBoxes):
def __init__(self, parent, title, message):
super().__init__(parent, title, message)
image = tk.PhotoImage(file="crazy_error_logo.png")
error_label = ttk.Label(self, image=image)
error_label.image = image
error_label.grid(row=0, column=0, pady=15)
message_label = ttk.Label(self, text=message)
message_label.grid(row=0, column=1, padx=15, pady=15)
ok_button = ttk.Button(self, text="Ok", command=self.destroy)
ok_button.grid(row=1, column=0, columnspan=2, padx=15, pady=15)
self.wait_window(self)
class CustomShowInfo(CustomMessageBoxes):
def __init__(self, parent, title, message):
super().__init__(parent, title, message)
image = tk.PhotoImage(file="crazy_showinfo_logo.png")
info_label = ttk.Label(self, image=image)
info_label.image = image
info_label.grid(row=0, column=0, pady=15)
message_label = ttk.Label(self, text=message)
message_label.grid(row=0, column=1, padx=15, pady=15)
ok_button = ttk.Button(self, text="Ok", command=self.destroy)
ok_button.grid(row=1, column=0, columnspan=2, padx=15, pady=15)
self.wait_window(self)
class CustomAskyesno(CustomMessageBoxes):
def __init__(self, parent, title, message):
super().__init__(parent, title, message)
def yes_func():
self.destroy()
return True
def no_func():
self.destroy()
return False
image = tk.PhotoImage(file="crazy_askyesno_logo.png")
error_label = ttk.Label(self, image=image)
error_label.image = image
error_label.grid(row=0, column=0, pady=15)
message_label = ttk.Label(self, text=message)
message_label.grid(row=0, column=1, padx=15, pady=15)
yes_button = ttk.Button(self, text="Yes", command=yes_func)
yes_button.grid(row=1, column=0, padx=15, pady=15)
no_button = ttk.Button(self, text="No", command=no_func)
no_button.grid(row=1, column=1, padx=15, pady=15)
self.wait_window(self)
def custom_showerror(parent, title=None, message=None):
CustomShowError(parent, title, message)
def custom_showinfo(parent, title=None, message=None):
CustomShowInfo(parent, title, message)
def custom_askyesno(parent, title=None, message=None):
CustomAskyesno(parent, title, message)