@@ -41,85 +41,95 @@ def showAboutTurtle():
4141
4242class DemoWindow (object ):
4343
44- def __init__ (self , filename = None ): #, root=None):
44+ def __init__ (self , filename = None ):
4545 self .root = root = turtle ._root = Tk ()
46+ root .title ('Python turtle-graphics examples' )
4647 root .wm_protocol ("WM_DELETE_WINDOW" , self ._destroy )
4748
48- #################
49- self .mBar = Frame (root , relief = RAISED , borderwidth = 2 )
50- self .mBar .pack (fill = X )
49+ root .grid_rowconfigure (1 , weight = 1 )
50+ root .grid_columnconfigure (0 , weight = 1 )
51+ root .grid_columnconfigure (1 , minsize = 90 , weight = 1 )
52+ root .grid_columnconfigure (2 , minsize = 90 , weight = 1 )
53+ root .grid_columnconfigure (3 , minsize = 90 , weight = 1 )
5154
55+ self .mBar = Frame (root , relief = RAISED , borderwidth = 2 )
5256 self .ExamplesBtn = self .makeLoadDemoMenu ()
5357 self .OptionsBtn = self .makeHelpMenu ()
54- self .mBar .tk_menuBar (self .ExamplesBtn , self .OptionsBtn ) #, QuitBtn)
58+ self .mBar .tk_menuBar (self .ExamplesBtn , self .OptionsBtn )
59+ self .mBar .grid (row = 0 , columnspan = 4 , sticky = 'news' )
60+
61+ pane = PanedWindow (orient = HORIZONTAL , sashwidth = 5 ,
62+ sashrelief = SOLID , bg = '#ddd' )
63+ pane .add (self .makeTextFrame (pane ))
64+ pane .add (self .makeGraphFrame (pane ))
65+ pane .grid (row = 1 , columnspan = 4 , sticky = 'news' )
66+
67+ self .output_lbl = Label (root , height = 1 , text = " --- " , bg = "#ddf" ,
68+ font = ("Arial" , 16 , 'normal' ), borderwidth = 2 ,
69+ relief = RIDGE )
70+ self .start_btn = Button (root , text = " START " , font = btnfont ,
71+ fg = "white" , disabledforeground = "#fed" ,
72+ command = self .startDemo )
73+ self .stop_btn = Button (root , text = " STOP " , font = btnfont ,
74+ fg = "white" , disabledforeground = "#fed" ,
75+ command = self .stopIt )
76+ self .clear_btn = Button (root , text = " CLEAR " , font = btnfont ,
77+ fg = "white" , disabledforeground = "#fed" ,
78+ command = self .clearCanvas )
79+ self .output_lbl .grid (row = 2 , column = 0 , sticky = 'news' , padx = (0 ,5 ))
80+ self .start_btn .grid (row = 2 , column = 1 , sticky = 'ew' )
81+ self .stop_btn .grid (row = 2 , column = 2 , sticky = 'ew' )
82+ self .clear_btn .grid (row = 2 , column = 3 , sticky = 'ew' )
83+
84+ Percolator (self .text ).insertfilter (ColorDelegator ())
85+ self .dirty = False
86+ self .exitflag = False
87+ if filename :
88+ self .loadfile (filename )
89+ self .configGUI (NORMAL , DISABLED , DISABLED , DISABLED ,
90+ "Choose example from menu" , "black" )
91+ self .state = STARTUP
5592
56- root .title ('Python turtle-graphics examples' )
57- #################
58- self .left_frame = left_frame = Frame (root )
59- self .text_frame = text_frame = Frame (left_frame )
60- self .vbar = vbar = Scrollbar (text_frame , name = 'vbar' )
61- self .text = text = Text (text_frame ,
62- name = 'text' , padx = 5 , wrap = 'none' ,
63- width = 45 )
93+
94+ def onResize (self , event ):
95+ cwidth = self ._canvas .winfo_width ()
96+ cheight = self ._canvas .winfo_height ()
97+ self ._canvas .xview_moveto (0.5 * (self .canvwidth - cwidth )/ self .canvwidth )
98+ self ._canvas .yview_moveto (0.5 * (self .canvheight - cheight )/ self .canvheight )
99+
100+ def makeTextFrame (self , root ):
101+ self .text_frame = text_frame = Frame (root )
102+ self .text = text = Text (text_frame , name = 'text' , padx = 5 ,
103+ wrap = 'none' , width = 45 )
104+
105+ self .vbar = vbar = Scrollbar (text_frame , name = 'vbar' )
64106 vbar ['command' ] = text .yview
65107 vbar .pack (side = LEFT , fill = Y )
66- #####################
67- self .hbar = hbar = Scrollbar (text_frame , name = 'hbar' , orient = HORIZONTAL )
108+ self .hbar = hbar = Scrollbar (text_frame , name = 'hbar' , orient = HORIZONTAL )
68109 hbar ['command' ] = text .xview
69110 hbar .pack (side = BOTTOM , fill = X )
70- #####################
111+
112+ text ['font' ] = txtfont
71113 text ['yscrollcommand' ] = vbar .set
72- text .config (font = txtfont )
73- text .config (xscrollcommand = hbar .set )
74- text .pack (side = LEFT , fill = Y , expand = 1 )
75- #####################
76- self .output_lbl = Label (left_frame , height = 1 ,text = " --- " , bg = "#ddf" ,
77- font = ("Arial" , 16 , 'normal' ))
78- self .output_lbl .pack (side = BOTTOM , expand = 0 , fill = X )
79- #####################
80- text_frame .pack (side = LEFT , fill = BOTH , expand = 0 )
81- left_frame .pack (side = LEFT , fill = BOTH , expand = 0 )
82- self .graph_frame = g_frame = Frame (root )
83-
84- turtle ._Screen ._root = g_frame
85- turtle ._Screen ._canvas = turtle .ScrolledCanvas (g_frame , 800 , 600 , 1000 , 800 )
86- #xturtle.Screen._canvas.pack(expand=1, fill="both")
114+ text ['xscrollcommand' ] = hbar .set
115+ text .pack (side = LEFT , fill = BOTH , expand = 1 )
116+ return text_frame
117+
118+ def makeGraphFrame (self , root ):
119+ turtle ._Screen ._root = root
120+ self .canvwidth = 1000
121+ self .canvheight = 800
122+ turtle ._Screen ._canvas = self ._canvas = canvas = turtle .ScrolledCanvas (
123+ root , 800 , 600 , self .canvwidth , self .canvheight )
124+ canvas .adjustScrolls ()
125+ canvas ._rootwindow .bind ('<Configure>' , self .onResize )
126+ canvas ._canvas ['borderwidth' ] = 0
127+
87128 self .screen = _s_ = turtle .Screen ()
88- #####
89129 turtle .TurtleScreen .__init__ (_s_ , _s_ ._canvas )
90- #####
91130 self .scanvas = _s_ ._canvas
92- #xturtle.RawTurtle.canvases = [self.scanvas]
93131 turtle .RawTurtle .screens = [_s_ ]
94-
95- self .scanvas .pack (side = TOP , fill = BOTH , expand = 1 )
96-
97- self .btn_frame = btn_frame = Frame (g_frame , height = 100 )
98- self .start_btn = Button (btn_frame , text = " START " , font = btnfont , fg = "white" ,
99- disabledforeground = "#fed" , command = self .startDemo )
100- self .start_btn .pack (side = LEFT , fill = X , expand = 1 )
101- self .stop_btn = Button (btn_frame , text = " STOP " , font = btnfont , fg = "white" ,
102- disabledforeground = "#fed" , command = self .stopIt )
103- self .stop_btn .pack (side = LEFT , fill = X , expand = 1 )
104- self .clear_btn = Button (btn_frame , text = " CLEAR " , font = btnfont , fg = "white" ,
105- disabledforeground = "#fed" , command = self .clearCanvas )
106- self .clear_btn .pack (side = LEFT , fill = X , expand = 1 )
107-
108- self .btn_frame .pack (side = TOP , fill = BOTH , expand = 0 )
109- self .graph_frame .pack (side = TOP , fill = BOTH , expand = 1 )
110-
111- Percolator (text ).insertfilter (ColorDelegator ())
112- self .dirty = False
113- self .exitflag = False
114- if filename :
115- self .loadfile (filename )
116- self .configGUI (NORMAL , DISABLED , DISABLED , DISABLED ,
117- "Choose example from menu" , "black" )
118- self .state = STARTUP
119-
120- def _destroy (self ):
121- self .root .destroy ()
122- sys .exit ()
132+ return canvas
123133
124134 def configGUI (self , menu , start , stop , clear , txt = "" , color = "blue" ):
125135 self .ExamplesBtn .config (state = menu )
@@ -145,9 +155,9 @@ def configGUI(self, menu, start, stop, clear, txt="", color="blue"):
145155
146156 self .output_lbl .config (text = txt , fg = color )
147157
148-
149158 def makeLoadDemoMenu (self ):
150- CmdBtn = Menubutton (self .mBar , text = 'Examples' , underline = 0 , font = menufont )
159+ CmdBtn = Menubutton (self .mBar , text = 'Examples' ,
160+ underline = 0 , font = menufont )
151161 CmdBtn .pack (side = LEFT , padx = "2m" )
152162 CmdBtn .menu = Menu (CmdBtn )
153163
@@ -180,7 +190,6 @@ def makeHelpMenu(self):
180190 def refreshCanvas (self ):
181191 if not self .dirty : return
182192 self .screen .clear ()
183- #self.screen.mode("standard")
184193 self .dirty = False
185194
186195 def loadfile (self , filename ):
@@ -238,10 +247,13 @@ def stopIt(self):
238247 self .configGUI (NORMAL , NORMAL , DISABLED , DISABLED ,
239248 "STOPPED!" , "red" )
240249 turtle .TurtleScreen ._RUNNING = False
241- #print "stopIT: exitflag = True"
242250 else :
243251 turtle .TurtleScreen ._RUNNING = False
244- #print "stopIt: exitflag = False"
252+
253+ def _destroy (self ):
254+ self .root .destroy ()
255+ sys .exit ()
256+
245257
246258if __name__ == '__main__' :
247259 demo = DemoWindow ()
0 commit comments