Python Forum
Turtle / turtle question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle / turtle question
#1
I know that Turtle is python v2 and turtle is v3.
To import is use this:
from turtle import Turtle
t =  Turtle()
and i can do everything i want.

But is that state of the art? If i do:
import turtle as t
I can do a lot of things, but many are missing, eg. the screen.title() option.
"import turtle as t" seems to be some strange mix with many attributes
referring to the v2 "Turtle" (capital), so it seems.

Does anybody have a clear view on the logic behind all this.
Why would i have to refer to a legacy Turtle when using turtle?
Huh
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
If you do import turtle as t, then t is the turtle module. If you do import turtle; t = turtle.Turtle(), then t is an instance of the turtle.Turtle class. The module and the class have different members.

Things are somewhat complicated by the fact that the turtle module implements a procedure-oriented interface (without explicit creation of a Turtle instance) and an object-oriented interface. If you want to be consistent with the rest of python, choose the the object-oriented interface, that is to say, create your own Turtle instance and work with it (that's where you say that you can do anything you want).
Reply
#3
(Oct-04-2020, 08:48 AM)Gribouillis Wrote: If you do import turtle as t, then t is the turtle module. If you do import turtle; t = turtle.Turtle(), then t is an instance of the turtle.Turtle class. The module and the class have different members.

Things are somewhat complicated by the fact that the turtle module implements a procedure-oriented interface (without explicit creation of a Turtle instance) and an object-oriented interface. If you want to be consistent with the rest of python, choose the the object-oriented interface, that is to say, create your own Turtle instance and work with it (that's where you say that you can do anything you want).

Crystal clear!
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Turtle. Pointers of the "arrow" direction of the vector. roomONmoon 1 628 Dec-09-2023, 11:49 PM
Last Post: deanhystad
  Module: Turtle issues Underscore 4 2,545 Sep-24-2021, 04:28 PM
Last Post: Underscore
  [Tkinter] Tkinter/turtle doevents DPaul 0 1,796 Sep-24-2020, 07:59 AM
Last Post: DPaul
  [Turtle] numinput and textinput do not work fgarciamoran 1 3,121 Apr-28-2020, 08:44 PM
Last Post: deanhystad
  Turtle fillcolor? bobgardner 2 1,820 Apr-12-2020, 07:13 PM
Last Post: bobgardner
  [Tkinter] Tkinter/Turtle Stopping and Starting Timers Cleanly robin73 2 3,306 Apr-01-2020, 07:31 AM
Last Post: robin73
  tkinter window and turtle window error 1885 3 6,625 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Turtle]Need help with moving a square on key press GalaxyCoyote 2 2,908 May-18-2019, 05:31 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020