@@ -107,85 +107,95 @@ def showAboutTurtle():
107107
108108class DemoWindow (object ):
109109
110- def __init__ (self , filename = None ): #, root=None):
110+ def __init__ (self , filename = None ):
111111 self .root = root = turtle ._root = Tk ()
112+ root .title ('Python turtle-graphics examples' )
112113 root .wm_protocol ("WM_DELETE_WINDOW" , self ._destroy )
113114
114- #################
115- self .mBar = Frame (root , relief = RAISED , borderwidth = 2 )
116- self .mBar .pack (fill = X )
115+ root .grid_rowconfigure (1 , weight = 1 )
116+ root .grid_columnconfigure (0 , weight = 1 )
117+ root .grid_columnconfigure (1 , minsize = 90 , weight = 1 )
118+ root .grid_columnconfigure (2 , minsize = 90 , weight = 1 )
119+ root .grid_columnconfigure (3 , minsize = 90 , weight = 1 )
117120
121+ self .mBar = Frame (root , relief = RAISED , borderwidth = 2 )
118122 self .ExamplesBtn = self .makeLoadDemoMenu ()
119123 self .OptionsBtn = self .makeHelpMenu ()
120- self .mBar .tk_menuBar (self .ExamplesBtn , self .OptionsBtn ) #, QuitBtn)
124+ self .mBar .tk_menuBar (self .ExamplesBtn , self .OptionsBtn )
125+ self .mBar .grid (row = 0 , columnspan = 4 , sticky = 'news' )
126+
127+ pane = PanedWindow (orient = HORIZONTAL , sashwidth = 5 ,
128+ sashrelief = SOLID , bg = '#ddd' )
129+ pane .add (self .makeTextFrame (pane ))
130+ pane .add (self .makeGraphFrame (pane ))
131+ pane .grid (row = 1 , columnspan = 4 , sticky = 'news' )
132+
133+ self .output_lbl = Label (root , height = 1 , text = " --- " , bg = "#ddf" ,
134+ font = ("Arial" , 16 , 'normal' ), borderwidth = 2 ,
135+ relief = RIDGE )
136+ self .start_btn = Button (root , text = " START " , font = btnfont ,
137+ fg = "white" , disabledforeground = "#fed" ,
138+ command = self .startDemo )
139+ self .stop_btn = Button (root , text = " STOP " , font = btnfont ,
140+ fg = "white" , disabledforeground = "#fed" ,
141+ command = self .stopIt )
142+ self .clear_btn = Button (root , text = " CLEAR " , font = btnfont ,
143+ fg = "white" , disabledforeground = "#fed" ,
144+ command = self .clearCanvas )
145+ self .output_lbl .grid (row = 2 , column = 0 , sticky = 'news' , padx = (0 ,5 ))
146+ self .start_btn .grid (row = 2 , column = 1 , sticky = 'ew' )
147+ self .stop_btn .grid (row = 2 , column = 2 , sticky = 'ew' )
148+ self .clear_btn .grid (row = 2 , column = 3 , sticky = 'ew' )
149+
150+ Percolator (self .text ).insertfilter (ColorDelegator ())
151+ self .dirty = False
152+ self .exitflag = False
153+ if filename :
154+ self .loadfile (filename )
155+ self .configGUI (NORMAL , DISABLED , DISABLED , DISABLED ,
156+ "Choose example from menu" , "black" )
157+ self .state = STARTUP
121158
122- root .title ('Python turtle-graphics examples' )
123- #################
124- self .left_frame = left_frame = Frame (root )
125- self .text_frame = text_frame = Frame (left_frame )
126- self .vbar = vbar = Scrollbar (text_frame , name = 'vbar' )
127- self .text = text = Text (text_frame ,
128- name = 'text' , padx = 5 , wrap = 'none' ,
129- width = 45 )
159+
160+ def onResize (self , event ):
161+ cwidth = self ._canvas .winfo_width ()
162+ cheight = self ._canvas .winfo_height ()
163+ self ._canvas .xview_moveto (0.5 * (self .canvwidth - cwidth )/ self .canvwidth )
164+ self ._canvas .yview_moveto (0.5 * (self .canvheight - cheight )/ self .canvheight )
165+
166+ def makeTextFrame (self , root ):
167+ self .text_frame = text_frame = Frame (root )
168+ self .text = text = Text (text_frame , name = 'text' , padx = 5 ,
169+ wrap = 'none' , width = 45 )
170+
171+ self .vbar = vbar = Scrollbar (text_frame , name = 'vbar' )
130172 vbar ['command' ] = text .yview
131173 vbar .pack (side = LEFT , fill = Y )
132- #####################
133- self .hbar = hbar = Scrollbar (text_frame , name = 'hbar' , orient = HORIZONTAL )
174+ self .hbar = hbar = Scrollbar (text_frame , name = 'hbar' , orient = HORIZONTAL )
134175 hbar ['command' ] = text .xview
135176 hbar .pack (side = BOTTOM , fill = X )
136- #####################
177+
178+ text ['font' ] = txtfont
137179 text ['yscrollcommand' ] = vbar .set
138- text .config (font = txtfont )
139- text .config (xscrollcommand = hbar .set )
140- text .pack (side = LEFT , fill = Y , expand = 1 )
141- #####################
142- self .output_lbl = Label (left_frame , height = 1 ,text = " --- " , bg = "#ddf" ,
143- font = ("Arial" , 16 , 'normal' ))
144- self .output_lbl .pack (side = BOTTOM , expand = 0 , fill = X )
145- #####################
146- text_frame .pack (side = LEFT , fill = BOTH , expand = 0 )
147- left_frame .pack (side = LEFT , fill = BOTH , expand = 0 )
148- self .graph_frame = g_frame = Frame (root )
149-
150- turtle ._Screen ._root = g_frame
151- turtle ._Screen ._canvas = turtle .ScrolledCanvas (g_frame , 800 , 600 , 1000 , 800 )
152- #xturtle.Screen._canvas.pack(expand=1, fill="both")
180+ text ['xscrollcommand' ] = hbar .set
181+ text .pack (side = LEFT , fill = BOTH , expand = 1 )
182+ return text_frame
183+
184+ def makeGraphFrame (self , root ):
185+ turtle ._Screen ._root = root
186+ self .canvwidth = 1000
187+ self .canvheight = 800
188+ turtle ._Screen ._canvas = self ._canvas = canvas = turtle .ScrolledCanvas (
189+ root , 800 , 600 , self .canvwidth , self .canvheight )
190+ canvas .adjustScrolls ()
191+ canvas ._rootwindow .bind ('<Configure>' , self .onResize )
192+ canvas ._canvas ['borderwidth' ] = 0
193+
153194 self .screen = _s_ = turtle .Screen ()
154- #####
155195 turtle .TurtleScreen .__init__ (_s_ , _s_ ._canvas )
156- #####
157196 self .scanvas = _s_ ._canvas
158- #xturtle.RawTurtle.canvases = [self.scanvas]
159197 turtle .RawTurtle .screens = [_s_ ]
160-
161- self .scanvas .pack (side = TOP , fill = BOTH , expand = 1 )
162-
163- self .btn_frame = btn_frame = Frame (g_frame , height = 100 )
164- self .start_btn = Button (btn_frame , text = " START " , font = btnfont , fg = "white" ,
165- disabledforeground = "#fed" , command = self .startDemo )
166- self .start_btn .pack (side = LEFT , fill = X , expand = 1 )
167- self .stop_btn = Button (btn_frame , text = " STOP " , font = btnfont , fg = "white" ,
168- disabledforeground = "#fed" , command = self .stopIt )
169- self .stop_btn .pack (side = LEFT , fill = X , expand = 1 )
170- self .clear_btn = Button (btn_frame , text = " CLEAR " , font = btnfont , fg = "white" ,
171- disabledforeground = "#fed" , command = self .clearCanvas )
172- self .clear_btn .pack (side = LEFT , fill = X , expand = 1 )
173-
174- self .btn_frame .pack (side = TOP , fill = BOTH , expand = 0 )
175- self .graph_frame .pack (side = TOP , fill = BOTH , expand = 1 )
176-
177- Percolator (text ).insertfilter (ColorDelegator ())
178- self .dirty = False
179- self .exitflag = False
180- if filename :
181- self .loadfile (filename )
182- self .configGUI (NORMAL , DISABLED , DISABLED , DISABLED ,
183- "Choose example from menu" , "black" )
184- self .state = STARTUP
185-
186- def _destroy (self ):
187- self .root .destroy ()
188- sys .exit ()
198+ return canvas
189199
190200 def configGUI (self , menu , start , stop , clear , txt = "" , color = "blue" ):
191201 self .ExamplesBtn .config (state = menu )
@@ -211,9 +221,9 @@ def configGUI(self, menu, start, stop, clear, txt="", color="blue"):
211221
212222 self .output_lbl .config (text = txt , fg = color )
213223
214-
215224 def makeLoadDemoMenu (self ):
216- CmdBtn = Menubutton (self .mBar , text = 'Examples' , underline = 0 , font = menufont )
225+ CmdBtn = Menubutton (self .mBar , text = 'Examples' ,
226+ underline = 0 , font = menufont )
217227 CmdBtn .pack (side = LEFT , padx = "2m" )
218228 CmdBtn .menu = Menu (CmdBtn )
219229
@@ -246,7 +256,6 @@ def makeHelpMenu(self):
246256 def refreshCanvas (self ):
247257 if not self .dirty : return
248258 self .screen .clear ()
249- #self.screen.mode("standard")
250259 self .dirty = False
251260
252261 def loadfile (self , filename ):
@@ -304,10 +313,13 @@ def stopIt(self):
304313 self .configGUI (NORMAL , NORMAL , DISABLED , DISABLED ,
305314 "STOPPED!" , "red" )
306315 turtle .TurtleScreen ._RUNNING = False
307- #print "stopIT: exitflag = True"
308316 else :
309317 turtle .TurtleScreen ._RUNNING = False
310- #print "stopIt: exitflag = False"
318+
319+ def _destroy (self ):
320+ self .root .destroy ()
321+ sys .exit ()
322+
311323
312324if __name__ == '__main__' :
313325 demo = DemoWindow ()
0 commit comments