Provides screen oriented methods like setbg etc. Only relies upon the methods of TurtleScreenBase and NOT upon components of the underlying graphics toolkit - which is Tkinter in this case.
| 852 | |
| 853 | |
| 854 | class TurtleScreen(TurtleScreenBase): |
| 855 | """Provides screen oriented methods like setbg etc. |
| 856 | |
| 857 | Only relies upon the methods of TurtleScreenBase and NOT |
| 858 | upon components of the underlying graphics toolkit - |
| 859 | which is Tkinter in this case. |
| 860 | """ |
| 861 | _RUNNING = True |
| 862 | |
| 863 | def __init__(self, cv, mode=_CFG["mode"], |
| 864 | colormode=_CFG["colormode"], delay=_CFG["delay"]): |
| 865 | TurtleScreenBase.__init__(self, cv) |
| 866 | |
| 867 | self._shapes = { |
| 868 | "arrow" : Shape("polygon", ((-10,0), (10,0), (0,10))), |
| 869 | "turtle" : Shape("polygon", ((0,16), (-2,14), (-1,10), (-4,7), |
| 870 | (-7,9), (-9,8), (-6,5), (-7,1), (-5,-3), (-8,-6), |
| 871 | (-6,-8), (-4,-5), (0,-7), (4,-5), (6,-8), (8,-6), |
| 872 | (5,-3), (7,1), (6,5), (9,8), (7,9), (4,7), (1,10), |
| 873 | (2,14))), |
| 874 | "circle" : Shape("polygon", ((10,0), (9.51,3.09), (8.09,5.88), |
| 875 | (5.88,8.09), (3.09,9.51), (0,10), (-3.09,9.51), |
| 876 | (-5.88,8.09), (-8.09,5.88), (-9.51,3.09), (-10,0), |
| 877 | (-9.51,-3.09), (-8.09,-5.88), (-5.88,-8.09), |
| 878 | (-3.09,-9.51), (-0.00,-10.00), (3.09,-9.51), |
| 879 | (5.88,-8.09), (8.09,-5.88), (9.51,-3.09))), |
| 880 | "square" : Shape("polygon", ((10,-10), (10,10), (-10,10), |
| 881 | (-10,-10))), |
| 882 | "triangle" : Shape("polygon", ((10,-5.77), (0,11.55), |
| 883 | (-10,-5.77))), |
| 884 | "classic": Shape("polygon", ((0,0),(-5,-9),(0,-7),(5,-9))), |
| 885 | "blank" : Shape("image", self._blankimage()) |
| 886 | } |
| 887 | |
| 888 | self._bgpics = {"nopic" : ""} |
| 889 | |
| 890 | self._mode = mode |
| 891 | self._delayvalue = delay |
| 892 | self._colormode = _CFG["colormode"] |
| 893 | self._keys = [] |
| 894 | self.clear() |
| 895 | if sys.platform == 'darwin': |
| 896 | # Force Turtle window to the front on OS X. This is needed because |
| 897 | # the Turtle window will show behind the Terminal window when you |
| 898 | # start the demo from the command line. |
| 899 | rootwindow = cv.winfo_toplevel() |
| 900 | rootwindow.call('wm', 'attributes', '.', '-topmost', '1') |
| 901 | rootwindow.call('wm', 'attributes', '.', '-topmost', '0') |
| 902 | |
| 903 | def clear(self): |
| 904 | """Delete all drawings and all turtles from the TurtleScreen. |
| 905 | |
| 906 | No argument. |
| 907 | |
| 908 | Reset empty TurtleScreen to its initial state: white background, |
| 909 | no backgroundimage, no eventbindings and tracing on. |
| 910 | |
| 911 | Example (for a TurtleScreen instance named screen): |