Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: turtle.py
#
[0] Fix | Delete
# turtle.py: a Tkinter based turtle graphics module for Python
[1] Fix | Delete
# Version 1.1b - 4. 5. 2009
[2] Fix | Delete
#
[3] Fix | Delete
# Copyright (C) 2006 - 2010 Gregor Lingl
[4] Fix | Delete
# email: glingl@aon.at
[5] Fix | Delete
#
[6] Fix | Delete
# This software is provided 'as-is', without any express or implied
[7] Fix | Delete
# warranty. In no event will the authors be held liable for any damages
[8] Fix | Delete
# arising from the use of this software.
[9] Fix | Delete
#
[10] Fix | Delete
# Permission is granted to anyone to use this software for any purpose,
[11] Fix | Delete
# including commercial applications, and to alter it and redistribute it
[12] Fix | Delete
# freely, subject to the following restrictions:
[13] Fix | Delete
#
[14] Fix | Delete
# 1. The origin of this software must not be misrepresented; you must not
[15] Fix | Delete
# claim that you wrote the original software. If you use this software
[16] Fix | Delete
# in a product, an acknowledgment in the product documentation would be
[17] Fix | Delete
# appreciated but is not required.
[18] Fix | Delete
# 2. Altered source versions must be plainly marked as such, and must not be
[19] Fix | Delete
# misrepresented as being the original software.
[20] Fix | Delete
# 3. This notice may not be removed or altered from any source distribution.
[21] Fix | Delete
[22] Fix | Delete
[23] Fix | Delete
"""
[24] Fix | Delete
Turtle graphics is a popular way for introducing programming to
[25] Fix | Delete
kids. It was part of the original Logo programming language developed
[26] Fix | Delete
by Wally Feurzig and Seymour Papert in 1966.
[27] Fix | Delete
[28] Fix | Delete
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it
[29] Fix | Delete
the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
[30] Fix | Delete
the direction it is facing, drawing a line as it moves. Give it the
[31] Fix | Delete
command turtle.right(25), and it rotates in-place 25 degrees clockwise.
[32] Fix | Delete
[33] Fix | Delete
By combining together these and similar commands, intricate shapes and
[34] Fix | Delete
pictures can easily be drawn.
[35] Fix | Delete
[36] Fix | Delete
----- turtle.py
[37] Fix | Delete
[38] Fix | Delete
This module is an extended reimplementation of turtle.py from the
[39] Fix | Delete
Python standard distribution up to Python 2.5. (See: http://www.python.org)
[40] Fix | Delete
[41] Fix | Delete
It tries to keep the merits of turtle.py and to be (nearly) 100%
[42] Fix | Delete
compatible with it. This means in the first place to enable the
[43] Fix | Delete
learning programmer to use all the commands, classes and methods
[44] Fix | Delete
interactively when using the module from within IDLE run with
[45] Fix | Delete
the -n switch.
[46] Fix | Delete
[47] Fix | Delete
Roughly it has the following features added:
[48] Fix | Delete
[49] Fix | Delete
- Better animation of the turtle movements, especially of turning the
[50] Fix | Delete
turtle. So the turtles can more easily be used as a visual feedback
[51] Fix | Delete
instrument by the (beginning) programmer.
[52] Fix | Delete
[53] Fix | Delete
- Different turtle shapes, gif-images as turtle shapes, user defined
[54] Fix | Delete
and user controllable turtle shapes, among them compound
[55] Fix | Delete
(multicolored) shapes. Turtle shapes can be stretched and tilted, which
[56] Fix | Delete
makes turtles very versatile geometrical objects.
[57] Fix | Delete
[58] Fix | Delete
- Fine control over turtle movement and screen updates via delay(),
[59] Fix | Delete
and enhanced tracer() and speed() methods.
[60] Fix | Delete
[61] Fix | Delete
- Aliases for the most commonly used commands, like fd for forward etc.,
[62] Fix | Delete
following the early Logo traditions. This reduces the boring work of
[63] Fix | Delete
typing long sequences of commands, which often occur in a natural way
[64] Fix | Delete
when kids try to program fancy pictures on their first encounter with
[65] Fix | Delete
turtle graphics.
[66] Fix | Delete
[67] Fix | Delete
- Turtles now have an undo()-method with configurable undo-buffer.
[68] Fix | Delete
[69] Fix | Delete
- Some simple commands/methods for creating event driven programs
[70] Fix | Delete
(mouse-, key-, timer-events). Especially useful for programming games.
[71] Fix | Delete
[72] Fix | Delete
- A scrollable Canvas class. The default scrollable Canvas can be
[73] Fix | Delete
extended interactively as needed while playing around with the turtle(s).
[74] Fix | Delete
[75] Fix | Delete
- A TurtleScreen class with methods controlling background color or
[76] Fix | Delete
background image, window and canvas size and other properties of the
[77] Fix | Delete
TurtleScreen.
[78] Fix | Delete
[79] Fix | Delete
- There is a method, setworldcoordinates(), to install a user defined
[80] Fix | Delete
coordinate-system for the TurtleScreen.
[81] Fix | Delete
[82] Fix | Delete
- The implementation uses a 2-vector class named Vec2D, derived from tuple.
[83] Fix | Delete
This class is public, so it can be imported by the application programmer,
[84] Fix | Delete
which makes certain types of computations very natural and compact.
[85] Fix | Delete
[86] Fix | Delete
- Appearance of the TurtleScreen and the Turtles at startup/import can be
[87] Fix | Delete
configured by means of a turtle.cfg configuration file.
[88] Fix | Delete
The default configuration mimics the appearance of the old turtle module.
[89] Fix | Delete
[90] Fix | Delete
- If configured appropriately the module reads in docstrings from a docstring
[91] Fix | Delete
dictionary in some different language, supplied separately and replaces
[92] Fix | Delete
the English ones by those read in. There is a utility function
[93] Fix | Delete
write_docstringdict() to write a dictionary with the original (English)
[94] Fix | Delete
docstrings to disc, so it can serve as a template for translations.
[95] Fix | Delete
[96] Fix | Delete
Behind the scenes there are some features included with possible
[97] Fix | Delete
extensions in mind. These will be commented and documented elsewhere.
[98] Fix | Delete
[99] Fix | Delete
"""
[100] Fix | Delete
[101] Fix | Delete
_ver = "turtle 1.1b- - for Python 3.1 - 4. 5. 2009"
[102] Fix | Delete
[103] Fix | Delete
# print(_ver)
[104] Fix | Delete
[105] Fix | Delete
import tkinter as TK
[106] Fix | Delete
import types
[107] Fix | Delete
import math
[108] Fix | Delete
import time
[109] Fix | Delete
import inspect
[110] Fix | Delete
import sys
[111] Fix | Delete
[112] Fix | Delete
from os.path import isfile, split, join
[113] Fix | Delete
from copy import deepcopy
[114] Fix | Delete
from tkinter import simpledialog
[115] Fix | Delete
[116] Fix | Delete
_tg_classes = ['ScrolledCanvas', 'TurtleScreen', 'Screen',
[117] Fix | Delete
'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D']
[118] Fix | Delete
_tg_screen_functions = ['addshape', 'bgcolor', 'bgpic', 'bye',
[119] Fix | Delete
'clearscreen', 'colormode', 'delay', 'exitonclick', 'getcanvas',
[120] Fix | Delete
'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
[121] Fix | Delete
'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer',
[122] Fix | Delete
'register_shape', 'resetscreen', 'screensize', 'setup',
[123] Fix | Delete
'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles', 'update',
[124] Fix | Delete
'window_height', 'window_width']
[125] Fix | Delete
_tg_turtle_functions = ['back', 'backward', 'begin_fill', 'begin_poly', 'bk',
[126] Fix | Delete
'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color',
[127] Fix | Delete
'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
[128] Fix | Delete
'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly',
[129] Fix | Delete
'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown',
[130] Fix | Delete
'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease', 'pd',
[131] Fix | Delete
'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position',
[132] Fix | Delete
'pu', 'radians', 'right', 'reset', 'resizemode', 'rt',
[133] Fix | Delete
'seth', 'setheading', 'setpos', 'setposition', 'settiltangle',
[134] Fix | Delete
'setundobuffer', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle',
[135] Fix | Delete
'speed', 'st', 'stamp', 'tilt', 'tiltangle', 'towards',
[136] Fix | Delete
'turtlesize', 'undo', 'undobufferentries', 'up', 'width',
[137] Fix | Delete
'write', 'xcor', 'ycor']
[138] Fix | Delete
_tg_utilities = ['write_docstringdict', 'done']
[139] Fix | Delete
[140] Fix | Delete
__all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
[141] Fix | Delete
_tg_utilities + ['Terminator']) # + _math_functions)
[142] Fix | Delete
[143] Fix | Delete
_alias_list = ['addshape', 'backward', 'bk', 'fd', 'ht', 'lt', 'pd', 'pos',
[144] Fix | Delete
'pu', 'rt', 'seth', 'setpos', 'setposition', 'st',
[145] Fix | Delete
'turtlesize', 'up', 'width']
[146] Fix | Delete
[147] Fix | Delete
_CFG = {"width" : 0.5, # Screen
[148] Fix | Delete
"height" : 0.75,
[149] Fix | Delete
"canvwidth" : 400,
[150] Fix | Delete
"canvheight": 300,
[151] Fix | Delete
"leftright": None,
[152] Fix | Delete
"topbottom": None,
[153] Fix | Delete
"mode": "standard", # TurtleScreen
[154] Fix | Delete
"colormode": 1.0,
[155] Fix | Delete
"delay": 10,
[156] Fix | Delete
"undobuffersize": 1000, # RawTurtle
[157] Fix | Delete
"shape": "classic",
[158] Fix | Delete
"pencolor" : "black",
[159] Fix | Delete
"fillcolor" : "black",
[160] Fix | Delete
"resizemode" : "noresize",
[161] Fix | Delete
"visible" : True,
[162] Fix | Delete
"language": "english", # docstrings
[163] Fix | Delete
"exampleturtle": "turtle",
[164] Fix | Delete
"examplescreen": "screen",
[165] Fix | Delete
"title": "Python Turtle Graphics",
[166] Fix | Delete
"using_IDLE": False
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
def config_dict(filename):
[170] Fix | Delete
"""Convert content of config-file into dictionary."""
[171] Fix | Delete
with open(filename, "r") as f:
[172] Fix | Delete
cfglines = f.readlines()
[173] Fix | Delete
cfgdict = {}
[174] Fix | Delete
for line in cfglines:
[175] Fix | Delete
line = line.strip()
[176] Fix | Delete
if not line or line.startswith("#"):
[177] Fix | Delete
continue
[178] Fix | Delete
try:
[179] Fix | Delete
key, value = line.split("=")
[180] Fix | Delete
except ValueError:
[181] Fix | Delete
print("Bad line in config-file %s:\n%s" % (filename,line))
[182] Fix | Delete
continue
[183] Fix | Delete
key = key.strip()
[184] Fix | Delete
value = value.strip()
[185] Fix | Delete
if value in ["True", "False", "None", "''", '""']:
[186] Fix | Delete
value = eval(value)
[187] Fix | Delete
else:
[188] Fix | Delete
try:
[189] Fix | Delete
if "." in value:
[190] Fix | Delete
value = float(value)
[191] Fix | Delete
else:
[192] Fix | Delete
value = int(value)
[193] Fix | Delete
except ValueError:
[194] Fix | Delete
pass # value need not be converted
[195] Fix | Delete
cfgdict[key] = value
[196] Fix | Delete
return cfgdict
[197] Fix | Delete
[198] Fix | Delete
def readconfig(cfgdict):
[199] Fix | Delete
"""Read config-files, change configuration-dict accordingly.
[200] Fix | Delete
[201] Fix | Delete
If there is a turtle.cfg file in the current working directory,
[202] Fix | Delete
read it from there. If this contains an importconfig-value,
[203] Fix | Delete
say 'myway', construct filename turtle_mayway.cfg else use
[204] Fix | Delete
turtle.cfg and read it from the import-directory, where
[205] Fix | Delete
turtle.py is located.
[206] Fix | Delete
Update configuration dictionary first according to config-file,
[207] Fix | Delete
in the import directory, then according to config-file in the
[208] Fix | Delete
current working directory.
[209] Fix | Delete
If no config-file is found, the default configuration is used.
[210] Fix | Delete
"""
[211] Fix | Delete
default_cfg = "turtle.cfg"
[212] Fix | Delete
cfgdict1 = {}
[213] Fix | Delete
cfgdict2 = {}
[214] Fix | Delete
if isfile(default_cfg):
[215] Fix | Delete
cfgdict1 = config_dict(default_cfg)
[216] Fix | Delete
if "importconfig" in cfgdict1:
[217] Fix | Delete
default_cfg = "turtle_%s.cfg" % cfgdict1["importconfig"]
[218] Fix | Delete
try:
[219] Fix | Delete
head, tail = split(__file__)
[220] Fix | Delete
cfg_file2 = join(head, default_cfg)
[221] Fix | Delete
except Exception:
[222] Fix | Delete
cfg_file2 = ""
[223] Fix | Delete
if isfile(cfg_file2):
[224] Fix | Delete
cfgdict2 = config_dict(cfg_file2)
[225] Fix | Delete
_CFG.update(cfgdict2)
[226] Fix | Delete
_CFG.update(cfgdict1)
[227] Fix | Delete
[228] Fix | Delete
try:
[229] Fix | Delete
readconfig(_CFG)
[230] Fix | Delete
except Exception:
[231] Fix | Delete
print ("No configfile read, reason unknown")
[232] Fix | Delete
[233] Fix | Delete
[234] Fix | Delete
class Vec2D(tuple):
[235] Fix | Delete
"""A 2 dimensional vector class, used as a helper class
[236] Fix | Delete
for implementing turtle graphics.
[237] Fix | Delete
May be useful for turtle graphics programs also.
[238] Fix | Delete
Derived from tuple, so a vector is a tuple!
[239] Fix | Delete
[240] Fix | Delete
Provides (for a, b vectors, k number):
[241] Fix | Delete
a+b vector addition
[242] Fix | Delete
a-b vector subtraction
[243] Fix | Delete
a*b inner product
[244] Fix | Delete
k*a and a*k multiplication with scalar
[245] Fix | Delete
|a| absolute value of a
[246] Fix | Delete
a.rotate(angle) rotation
[247] Fix | Delete
"""
[248] Fix | Delete
def __new__(cls, x, y):
[249] Fix | Delete
return tuple.__new__(cls, (x, y))
[250] Fix | Delete
def __add__(self, other):
[251] Fix | Delete
return Vec2D(self[0]+other[0], self[1]+other[1])
[252] Fix | Delete
def __mul__(self, other):
[253] Fix | Delete
if isinstance(other, Vec2D):
[254] Fix | Delete
return self[0]*other[0]+self[1]*other[1]
[255] Fix | Delete
return Vec2D(self[0]*other, self[1]*other)
[256] Fix | Delete
def __rmul__(self, other):
[257] Fix | Delete
if isinstance(other, int) or isinstance(other, float):
[258] Fix | Delete
return Vec2D(self[0]*other, self[1]*other)
[259] Fix | Delete
return NotImplemented
[260] Fix | Delete
def __sub__(self, other):
[261] Fix | Delete
return Vec2D(self[0]-other[0], self[1]-other[1])
[262] Fix | Delete
def __neg__(self):
[263] Fix | Delete
return Vec2D(-self[0], -self[1])
[264] Fix | Delete
def __abs__(self):
[265] Fix | Delete
return (self[0]**2 + self[1]**2)**0.5
[266] Fix | Delete
def rotate(self, angle):
[267] Fix | Delete
"""rotate self counterclockwise by angle
[268] Fix | Delete
"""
[269] Fix | Delete
perp = Vec2D(-self[1], self[0])
[270] Fix | Delete
angle = angle * math.pi / 180.0
[271] Fix | Delete
c, s = math.cos(angle), math.sin(angle)
[272] Fix | Delete
return Vec2D(self[0]*c+perp[0]*s, self[1]*c+perp[1]*s)
[273] Fix | Delete
def __getnewargs__(self):
[274] Fix | Delete
return (self[0], self[1])
[275] Fix | Delete
def __repr__(self):
[276] Fix | Delete
return "(%.2f,%.2f)" % self
[277] Fix | Delete
[278] Fix | Delete
[279] Fix | Delete
##############################################################################
[280] Fix | Delete
### From here up to line : Tkinter - Interface for turtle.py ###
[281] Fix | Delete
### May be replaced by an interface to some different graphics toolkit ###
[282] Fix | Delete
##############################################################################
[283] Fix | Delete
[284] Fix | Delete
## helper functions for Scrolled Canvas, to forward Canvas-methods
[285] Fix | Delete
## to ScrolledCanvas class
[286] Fix | Delete
[287] Fix | Delete
def __methodDict(cls, _dict):
[288] Fix | Delete
"""helper function for Scrolled Canvas"""
[289] Fix | Delete
baseList = list(cls.__bases__)
[290] Fix | Delete
baseList.reverse()
[291] Fix | Delete
for _super in baseList:
[292] Fix | Delete
__methodDict(_super, _dict)
[293] Fix | Delete
for key, value in cls.__dict__.items():
[294] Fix | Delete
if type(value) == types.FunctionType:
[295] Fix | Delete
_dict[key] = value
[296] Fix | Delete
[297] Fix | Delete
def __methods(cls):
[298] Fix | Delete
"""helper function for Scrolled Canvas"""
[299] Fix | Delete
_dict = {}
[300] Fix | Delete
__methodDict(cls, _dict)
[301] Fix | Delete
return _dict.keys()
[302] Fix | Delete
[303] Fix | Delete
__stringBody = (
[304] Fix | Delete
'def %(method)s(self, *args, **kw): return ' +
[305] Fix | Delete
'self.%(attribute)s.%(method)s(*args, **kw)')
[306] Fix | Delete
[307] Fix | Delete
def __forwardmethods(fromClass, toClass, toPart, exclude = ()):
[308] Fix | Delete
### MANY CHANGES ###
[309] Fix | Delete
_dict_1 = {}
[310] Fix | Delete
__methodDict(toClass, _dict_1)
[311] Fix | Delete
_dict = {}
[312] Fix | Delete
mfc = __methods(fromClass)
[313] Fix | Delete
for ex in _dict_1.keys():
[314] Fix | Delete
if ex[:1] == '_' or ex[-1:] == '_' or ex in exclude or ex in mfc:
[315] Fix | Delete
pass
[316] Fix | Delete
else:
[317] Fix | Delete
_dict[ex] = _dict_1[ex]
[318] Fix | Delete
[319] Fix | Delete
for method, func in _dict.items():
[320] Fix | Delete
d = {'method': method, 'func': func}
[321] Fix | Delete
if isinstance(toPart, str):
[322] Fix | Delete
execString = \
[323] Fix | Delete
__stringBody % {'method' : method, 'attribute' : toPart}
[324] Fix | Delete
exec(execString, d)
[325] Fix | Delete
setattr(fromClass, method, d[method]) ### NEWU!
[326] Fix | Delete
[327] Fix | Delete
[328] Fix | Delete
class ScrolledCanvas(TK.Frame):
[329] Fix | Delete
"""Modeled after the scrolled canvas class from Grayons's Tkinter book.
[330] Fix | Delete
[331] Fix | Delete
Used as the default canvas, which pops up automatically when
[332] Fix | Delete
using turtle graphics functions or the Turtle class.
[333] Fix | Delete
"""
[334] Fix | Delete
def __init__(self, master, width=500, height=350,
[335] Fix | Delete
canvwidth=600, canvheight=500):
[336] Fix | Delete
TK.Frame.__init__(self, master, width=width, height=height)
[337] Fix | Delete
self._rootwindow = self.winfo_toplevel()
[338] Fix | Delete
self.width, self.height = width, height
[339] Fix | Delete
self.canvwidth, self.canvheight = canvwidth, canvheight
[340] Fix | Delete
self.bg = "white"
[341] Fix | Delete
self._canvas = TK.Canvas(master, width=width, height=height,
[342] Fix | Delete
bg=self.bg, relief=TK.SUNKEN, borderwidth=2)
[343] Fix | Delete
self.hscroll = TK.Scrollbar(master, command=self._canvas.xview,
[344] Fix | Delete
orient=TK.HORIZONTAL)
[345] Fix | Delete
self.vscroll = TK.Scrollbar(master, command=self._canvas.yview)
[346] Fix | Delete
self._canvas.configure(xscrollcommand=self.hscroll.set,
[347] Fix | Delete
yscrollcommand=self.vscroll.set)
[348] Fix | Delete
self.rowconfigure(0, weight=1, minsize=0)
[349] Fix | Delete
self.columnconfigure(0, weight=1, minsize=0)
[350] Fix | Delete
self._canvas.grid(padx=1, in_ = self, pady=1, row=0,
[351] Fix | Delete
column=0, rowspan=1, columnspan=1, sticky='news')
[352] Fix | Delete
self.vscroll.grid(padx=1, in_ = self, pady=1, row=0,
[353] Fix | Delete
column=1, rowspan=1, columnspan=1, sticky='news')
[354] Fix | Delete
self.hscroll.grid(padx=1, in_ = self, pady=1, row=1,
[355] Fix | Delete
column=0, rowspan=1, columnspan=1, sticky='news')
[356] Fix | Delete
self.reset()
[357] Fix | Delete
self._rootwindow.bind('<Configure>', self.onResize)
[358] Fix | Delete
[359] Fix | Delete
def reset(self, canvwidth=None, canvheight=None, bg = None):
[360] Fix | Delete
"""Adjust canvas and scrollbars according to given canvas size."""
[361] Fix | Delete
if canvwidth:
[362] Fix | Delete
self.canvwidth = canvwidth
[363] Fix | Delete
if canvheight:
[364] Fix | Delete
self.canvheight = canvheight
[365] Fix | Delete
if bg:
[366] Fix | Delete
self.bg = bg
[367] Fix | Delete
self._canvas.config(bg=bg,
[368] Fix | Delete
scrollregion=(-self.canvwidth//2, -self.canvheight//2,
[369] Fix | Delete
self.canvwidth//2, self.canvheight//2))
[370] Fix | Delete
self._canvas.xview_moveto(0.5*(self.canvwidth - self.width + 30) /
[371] Fix | Delete
self.canvwidth)
[372] Fix | Delete
self._canvas.yview_moveto(0.5*(self.canvheight- self.height + 30) /
[373] Fix | Delete
self.canvheight)
[374] Fix | Delete
self.adjustScrolls()
[375] Fix | Delete
[376] Fix | Delete
[377] Fix | Delete
def adjustScrolls(self):
[378] Fix | Delete
""" Adjust scrollbars according to window- and canvas-size.
[379] Fix | Delete
"""
[380] Fix | Delete
cwidth = self._canvas.winfo_width()
[381] Fix | Delete
cheight = self._canvas.winfo_height()
[382] Fix | Delete
self._canvas.xview_moveto(0.5*(self.canvwidth-cwidth)/self.canvwidth)
[383] Fix | Delete
self._canvas.yview_moveto(0.5*(self.canvheight-cheight)/self.canvheight)
[384] Fix | Delete
if cwidth < self.canvwidth or cheight < self.canvheight:
[385] Fix | Delete
self.hscroll.grid(padx=1, in_ = self, pady=1, row=1,
[386] Fix | Delete
column=0, rowspan=1, columnspan=1, sticky='news')
[387] Fix | Delete
self.vscroll.grid(padx=1, in_ = self, pady=1, row=0,
[388] Fix | Delete
column=1, rowspan=1, columnspan=1, sticky='news')
[389] Fix | Delete
else:
[390] Fix | Delete
self.hscroll.grid_forget()
[391] Fix | Delete
self.vscroll.grid_forget()
[392] Fix | Delete
[393] Fix | Delete
def onResize(self, event):
[394] Fix | Delete
"""self-explanatory"""
[395] Fix | Delete
self.adjustScrolls()
[396] Fix | Delete
[397] Fix | Delete
def bbox(self, *args):
[398] Fix | Delete
""" 'forward' method, which canvas itself has inherited...
[399] Fix | Delete
"""
[400] Fix | Delete
return self._canvas.bbox(*args)
[401] Fix | Delete
[402] Fix | Delete
def cget(self, *args, **kwargs):
[403] Fix | Delete
""" 'forward' method, which canvas itself has inherited...
[404] Fix | Delete
"""
[405] Fix | Delete
return self._canvas.cget(*args, **kwargs)
[406] Fix | Delete
[407] Fix | Delete
def config(self, *args, **kwargs):
[408] Fix | Delete
""" 'forward' method, which canvas itself has inherited...
[409] Fix | Delete
"""
[410] Fix | Delete
self._canvas.config(*args, **kwargs)
[411] Fix | Delete
[412] Fix | Delete
def bind(self, *args, **kwargs):
[413] Fix | Delete
""" 'forward' method, which canvas itself has inherited...
[414] Fix | Delete
"""
[415] Fix | Delete
self._canvas.bind(*args, **kwargs)
[416] Fix | Delete
[417] Fix | Delete
def unbind(self, *args, **kwargs):
[418] Fix | Delete
""" 'forward' method, which canvas itself has inherited...
[419] Fix | Delete
"""
[420] Fix | Delete
self._canvas.unbind(*args, **kwargs)
[421] Fix | Delete
[422] Fix | Delete
def focus_force(self):
[423] Fix | Delete
""" 'forward' method, which canvas itself has inherited...
[424] Fix | Delete
"""
[425] Fix | Delete
self._canvas.focus_force()
[426] Fix | Delete
[427] Fix | Delete
__forwardmethods(ScrolledCanvas, TK.Canvas, '_canvas')
[428] Fix | Delete
[429] Fix | Delete
[430] Fix | Delete
class _Root(TK.Tk):
[431] Fix | Delete
"""Root class for Screen based on Tkinter."""
[432] Fix | Delete
def __init__(self):
[433] Fix | Delete
TK.Tk.__init__(self)
[434] Fix | Delete
[435] Fix | Delete
def setupcanvas(self, width, height, cwidth, cheight):
[436] Fix | Delete
self._canvas = ScrolledCanvas(self, width, height, cwidth, cheight)
[437] Fix | Delete
self._canvas.pack(expand=1, fill="both")
[438] Fix | Delete
[439] Fix | Delete
def _getcanvas(self):
[440] Fix | Delete
return self._canvas
[441] Fix | Delete
[442] Fix | Delete
def set_geometry(self, width, height, startx, starty):
[443] Fix | Delete
self.geometry("%dx%d%+d%+d"%(width, height, startx, starty))
[444] Fix | Delete
[445] Fix | Delete
def ondestroy(self, destroy):
[446] Fix | Delete
self.wm_protocol("WM_DELETE_WINDOW", destroy)
[447] Fix | Delete
[448] Fix | Delete
def win_width(self):
[449] Fix | Delete
return self.winfo_screenwidth()
[450] Fix | Delete
[451] Fix | Delete
def win_height(self):
[452] Fix | Delete
return self.winfo_screenheight()
[453] Fix | Delete
[454] Fix | Delete
Canvas = TK.Canvas
[455] Fix | Delete
[456] Fix | Delete
[457] Fix | Delete
class TurtleScreenBase(object):
[458] Fix | Delete
"""Provide the basic graphics functionality.
[459] Fix | Delete
Interface between Tkinter and turtle.py.
[460] Fix | Delete
[461] Fix | Delete
To port turtle.py to some different graphics toolkit
[462] Fix | Delete
a corresponding TurtleScreenBase class has to be implemented.
[463] Fix | Delete
"""
[464] Fix | Delete
[465] Fix | Delete
def _blankimage(self):
[466] Fix | Delete
"""return a blank image object
[467] Fix | Delete
"""
[468] Fix | Delete
img = TK.PhotoImage(width=1, height=1, master=self.cv)
[469] Fix | Delete
img.blank()
[470] Fix | Delete
return img
[471] Fix | Delete
[472] Fix | Delete
def _image(self, filename):
[473] Fix | Delete
"""return an image object containing the
[474] Fix | Delete
imagedata from a gif-file named filename.
[475] Fix | Delete
"""
[476] Fix | Delete
return TK.PhotoImage(file=filename, master=self.cv)
[477] Fix | Delete
[478] Fix | Delete
def __init__(self, cv):
[479] Fix | Delete
self.cv = cv
[480] Fix | Delete
if isinstance(cv, ScrolledCanvas):
[481] Fix | Delete
w = self.cv.canvwidth
[482] Fix | Delete
h = self.cv.canvheight
[483] Fix | Delete
else: # expected: ordinary TK.Canvas
[484] Fix | Delete
w = int(self.cv.cget("width"))
[485] Fix | Delete
h = int(self.cv.cget("height"))
[486] Fix | Delete
self.cv.config(scrollregion = (-w//2, -h//2, w//2, h//2 ))
[487] Fix | Delete
self.canvwidth = w
[488] Fix | Delete
self.canvheight = h
[489] Fix | Delete
self.xscale = self.yscale = 1.0
[490] Fix | Delete
[491] Fix | Delete
def _createpoly(self):
[492] Fix | Delete
"""Create an invisible polygon item on canvas self.cv)
[493] Fix | Delete
"""
[494] Fix | Delete
return self.cv.create_polygon((0, 0, 0, 0, 0, 0), fill="", outline="")
[495] Fix | Delete
[496] Fix | Delete
def _drawpoly(self, polyitem, coordlist, fill=None,
[497] Fix | Delete
outline=None, width=None, top=False):
[498] Fix | Delete
"""Configure polygonitem polyitem according to provided
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function