22
33
44from Tkinter import *
5- import tktools
65
76
87class SimpleDialog :
98
109 def __init__ (self , master ,
1110 text = '' , buttons = [], default = None , cancel = None ,
1211 title = None , class_ = None ):
13- self .root = tktools .make_toplevel (master , title = title , class_ = class_ )
12+ if class_ :
13+ self .root = Toplevel (master , class_ = class_ )
14+ else :
15+ self .root = Toplevel (master )
16+ if title :
17+ self .root .title (title )
18+ self .root .iconname (title )
1419 self .message = Message (self .root , text = text , aspect = 400 )
1520 self .message .pack (expand = 1 , fill = BOTH )
1621 self .frame = Frame (self .root )
@@ -27,7 +32,28 @@ def __init__(self, master,
2732 b .config (relief = RIDGE , borderwidth = 8 )
2833 b .pack (side = LEFT , fill = BOTH , expand = 1 )
2934 self .root .protocol ('WM_DELETE_WINDOW' , self .wm_delete_window )
30- tktools .set_transient (self .root , master )
35+ self ._set_transient (master )
36+
37+ def _set_transient (self , master , relx = 0.5 , rely = 0.3 ):
38+ widget = self .root
39+ widget .withdraw () # Remain invisible while we figure out the geometry
40+ widget .transient (master )
41+ widget .update_idletasks () # Actualize geometry information
42+ if master .winfo_ismapped ():
43+ m_width = master .winfo_width ()
44+ m_height = master .winfo_height ()
45+ m_x = master .winfo_rootx ()
46+ m_y = master .winfo_rooty ()
47+ else :
48+ m_width = master .winfo_screenwidth ()
49+ m_height = master .winfo_screenheight ()
50+ m_x = m_y = 0
51+ w_width = widget .winfo_reqwidth ()
52+ w_height = widget .winfo_reqheight ()
53+ x = m_x + (m_width - w_width ) * relx
54+ y = m_y + (m_height - w_height ) * rely
55+ widget .geometry ("+%d+%d" % (x , y ))
56+ widget .deiconify () # Become visible at the desired location
3157
3258 def go (self ):
3359 self .root .grab_set ()
@@ -58,8 +84,8 @@ def doit(root=root):
5884 d = SimpleDialog (root ,
5985 text = "This is a test dialog. "
6086 "Would this have been an actual dialog, "
61- "the buttons below would have glowed "
62- "in soft pink light. "
87+ "the buttons below would have been glowing "
88+ "in soft pink light.\n "
6389 "Do you believe this?" ,
6490 buttons = ["Yes" , "No" , "Cancel" ],
6591 default = 0 ,
0 commit comments