-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyToplevel.py
More file actions
34 lines (30 loc) · 1.09 KB
/
myToplevel.py
File metadata and controls
34 lines (30 loc) · 1.09 KB
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
from tkinter import Toplevel
class MyToplevel(Toplevel):
def __init__(self,master,width=200,height=60,bg="white"):
Toplevel.__init__(self,master=master,width=width,height=height,bg=bg)
x=str(self.master.winfo_rootx()+self.master.winfo_width()//2-width//2)
y=str(self.master.winfo_rooty()+self.master.winfo_height()//2-height//2)
self.geometry("+"+x+"+"+y)
self.wait_visibility()
grab=False
while not grab:
try:
self.grab_set()
grab=True
except:
grab=False
def deiconify(self):
x=str(self.master.winfo_rootx()+self.master.winfo_width()//2-self.winfo_width()//2)
y=str(self.master.winfo_rooty()+self.master.winfo_height()//2-self.winfo_height()//2)
self.geometry("+"+x+"+"+y)
Toplevel.deiconify(self)
grab=False
while not grab:
try:
self.grab_set()
grab=True
except:
grab=False
def withdraw(self):
Toplevel.withdraw(self)
self.grab_release()