Đầu vào bàn phím rùa Python

Đồ họa con rùa là một cách phổ biến để giới thiệu lập trình cho trẻ em. Nó là một phần của ngôn ngữ lập trình Logo ban đầu được phát triển bởi Wally Feurzeig, Seymour Papert và Cynthia Solomon vào năm 1967

Hãy tưởng tượng một con rùa robot bắt đầu từ [0, 0] trong mặt phẳng x-y. Sau một

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
9, đưa cho nó lệnh
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
0, và nó di chuyển [trên màn hình. ] 15 pixel theo hướng mà nó hướng tới, vẽ một đường khi nó di chuyển. Đưa cho nó lệnh
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1 và nó xoay tại chỗ 25 độ theo chiều kim đồng hồ

rùa sao

Rùa có thể vẽ các hình phức tạp bằng các chương trình lặp lại các bước di chuyển đơn giản

from turtle import *
color['red', 'yellow']
begin_fill[]
while True:
    forward[200]
    left[170]
    if abs[pos[]] >> turtle.setheading[90]
>>> turtle.heading[]
90.0
8 là sự triển khai lại mở rộng của mô-đun cùng tên từ bản phân phối tiêu chuẩn Python cho đến phiên bản Python 2. 5

Nó cố gắng giữ những ưu điểm của mô-đun rùa cũ và tương thích [gần như] 100% với nó. Điều này có nghĩa là ngay từ đầu phải cho phép người lập trình học sử dụng tất cả các lệnh, lớp và phương thức một cách tương tác khi sử dụng mô-đun từ bên trong IDLE chạy với công tắc

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
3

Mô-đun rùa cung cấp các nguyên mẫu đồ họa rùa, theo cả hai cách hướng đối tượng và hướng thủ tục. Bởi vì nó sử dụng

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4 cho đồ họa cơ bản, nên nó cần cài đặt phiên bản Python có hỗ trợ Tk

Giao diện hướng đối tượng về cơ bản sử dụng hai+hai lớp

  1. Lớp

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    5 định nghĩa cửa sổ đồ họa là sân chơi cho rùa vẽ. Trình xây dựng của nó cần một đối số là
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    6 hoặc
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    7. Nó nên được sử dụng khi
    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    8 được sử dụng như một phần của ứng dụng nào đó

    Hàm

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    9 trả về một đối tượng đơn lẻ của lớp con
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    5. Chức năng này nên được sử dụng khi
    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    8 được sử dụng như một công cụ độc lập để thực hiện đồ họa. Là một đối tượng đơn lẻ, không thể kế thừa từ lớp của nó

    Tất cả các phương thức của TurtleScreen/Screen cũng tồn tại dưới dạng hàm, tôi. e. như một phần của giao diện hướng thủ tục

  2. >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    402 [bí danh.
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    403] định nghĩa các đối tượng Rùa vẽ trên một
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    5. Hàm tạo của nó cần một Canvas, ScrolledCanvas hoặc TurtleScreen làm đối số, vì vậy các đối tượng RawTurtle biết nơi để vẽ

    Có nguồn gốc từ RawTurtle là phân lớp

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    405 [bí danh.
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    406], dựa trên “đối tượng”
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    407 được tạo tự động, nếu chưa có

    Tất cả các phương thức của RawTurtle/Turtle cũng tồn tại dưới dạng hàm, tôi. e. một phần của giao diện hướng thủ tục

Giao diện thủ tục cung cấp các chức năng bắt nguồn từ các phương thức của các lớp

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
407 và
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
405. Chúng có cùng tên với các phương thức tương ứng. Một đối tượng màn hình được tạo tự động bất cứ khi nào một hàm bắt nguồn từ phương thức Màn hình được gọi. Một đối tượng rùa [chưa được đặt tên] được tạo tự động bất cứ khi nào bất kỳ hàm nào bắt nguồn từ phương thức Rùa được gọi

Để sử dụng nhiều con rùa trên một màn hình, người ta phải sử dụng giao diện hướng đối tượng

Ghi chú

Trong tài liệu sau đây, danh sách đối số cho các hàm được đưa ra. Methods, of course, have the additional first argument self which is omitted here

Overview of available Turtle and Screen methods¶

Turtle methods¶

Turtle motionMove and draw

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
410 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
411

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
412 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
413 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
414

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
415 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
416

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
417 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
418

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
419 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
420 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
421

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
422

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
423

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
424 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
425

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
426

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
427

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
428

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
429

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
430

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
431

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
432

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
433

Cho biết trạng thái của Rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
434 .
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
435

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
436

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
437

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
438

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
439

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
440

Setting and measurement

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
441

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
442

Điều khiển bút Trạng thái vẽ

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
443.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
444.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
445

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
446.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
447.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
448

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
449.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
450

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
451

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
452

Kiểm soát màu sắc

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
453

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
454

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
455

đổ đầy

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
456

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
457

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
458

Kiểm soát bản vẽ nhiều hơn

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
459

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
460

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
461

Trạng thái rùaKhả năng hiển thị

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
462.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
463

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
464.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
465

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
466

Xuất hiện

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
467

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
468

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
469.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
470

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
471

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
472

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
473

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
474

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
475

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
476

Sử dụng các sự kiện

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
477

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
478

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
479

Phương pháp rùa đặc biệt

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
480

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
481

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
482

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
483

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
484.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
485

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
486

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
487

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
488

Các phương thức của TurtleScreen/Screen¶

Kiểm soát cửa sổ

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
489

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
490

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
491

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
492

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
493

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
494

kiểm soát hoạt hình

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
495

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
496

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
497

Sử dụng các sự kiện màn hình

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
498

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
499.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1200

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1201

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
477.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1203

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1204

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1205.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1206

Cài đặt và phương pháp đặc biệt

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1207

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1208

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1209

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1210

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1211.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1212

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1213

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1214

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1215

Phương thức nhập liệu

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1216

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1217

Các phương pháp dành riêng cho Màn hình

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1218

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1219

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1220

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1221

Các phương thức của RawTurtle/Turtle và các hàm tương ứng¶

Hầu hết các ví dụ trong phần này đề cập đến một cá thể Rùa có tên là

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
8

Chuyển động của rùa¶

rùa. về phía trước[khoảng cách] ¶ . turtle.fd[khoảng cách]

khoảng cách – một số [số nguyên hoặc số thực]

Di chuyển rùa về phía trước theo khoảng cách xác định, theo hướng rùa đang đi

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4

rùa. lùi lại[khoảng cách] ¶ . turtle.bk[khoảng cách] ¶ . turtle.lùi lại[khoảng cách]

khoảng cách - một con số

Di chuyển rùa lùi một đoạn, ngược với hướng rùa đi. Không thay đổi tiêu đề của rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
12

rùa. phải[góc] ¶ . turtle.rt[góc]

góc – một số [số nguyên hoặc số float]

Xoay rùa sang phải theo đơn vị góc. [Các đơn vị theo độ mặc định, nhưng có thể được đặt thông qua các hàm

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
441 và
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
442. ] Định hướng góc phụ thuộc vào chế độ con rùa, xem
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1207

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
40

rùa. trái[góc] ¶ . turtle.lt[góc]

góc – một số [số nguyên hoặc số float]

Xoay rùa sang trái theo đơn vị góc. [Các đơn vị theo độ mặc định, nhưng có thể được đặt thông qua các hàm

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
441 và
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
442. ] Định hướng góc phụ thuộc vào chế độ con rùa, xem
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1207

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
44

rùa. goto[x , y . =None]turtle.đặt vị trí[x , y . =None]turtle.vị trí đặt[x , y=None]¶Parameters
  • x – một số hoặc một cặp/vectơ số

  • y – một số hoặc

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229

Nếu y là

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, x phải là một cặp tọa độ hoặc một
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1231 [e. g. như được trả về bởi
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
435]

Di chuyển rùa đến một vị trí tuyệt đối. Nếu bút xuống, vẽ đường. Không thay đổi hướng của rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
49

rùa. setx[x]

x – một số [số nguyên hoặc số thực]

Đặt tọa độ đầu tiên của rùa thành x, giữ nguyên tọa độ thứ hai

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
50

rùa. bộ[y]

y – một số [số nguyên hoặc số thực]

Đặt tọa độ thứ hai của rùa thành y, giữ nguyên tọa độ đầu tiên

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
51

rùa. tiêu đề[to_angle] ¶ . turtle.seth[to_angle]

to_angle – một số [số nguyên hoặc số thực]

Đặt hướng của rùa thành to_angle. Dưới đây là một số hướng phổ biến theo độ

chế độ căn bản

chế độ logo

0 - đông

0 - bắc

90 - bắc

90 - đông

180 - tây

180 - nam

270 - nam

270 - tây

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0

rùa. nhà[]

Di chuyển con rùa đến điểm gốc – tọa độ [0,0] – và đặt tiêu đề của nó thành hướng bắt đầu [tùy thuộc vào chế độ, xem

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1207]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0

rùa. hình tròn[bán kính , phạm vi=None, steps=None]¶Parameters
  • bán kính - một số

  • phạm vi – một số [hoặc

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229]

  • các bước – một số nguyên [hoặc

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229]

Vẽ đường tròn có bán kính cho trước. Trung tâm là các đơn vị bán kính bên trái của con rùa; . Nếu phạm vi không được đưa ra, hãy vẽ toàn bộ vòng tròn. Nếu phạm vi không phải là một vòng tròn đầy đủ, một điểm cuối của vòng cung là vị trí bút hiện tại. Vẽ cung theo hướng ngược chiều kim đồng hồ nếu bán kính dương, ngược lại theo chiều kim đồng hồ. Cuối cùng, hướng của rùa được thay đổi theo mức độ

Vì hình tròn được xấp xỉ bằng một đa giác đều nội tiếp, các bước xác định số bước sẽ sử dụng. Nếu không được cung cấp, nó sẽ được tính toán tự động. Có thể được sử dụng để vẽ đa giác thông thường

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
40

rùa. chấm[kích thước=Không, *color]¶Parameters
  • size – một số nguyên >= 1 [nếu có]

  • màu – một chuỗi màu hoặc một bộ màu số

Vẽ một chấm tròn có kích thước đường kính, sử dụng màu. Nếu kích thước không được cung cấp, thì tối đa pensize+4 và 2*pensize được sử dụng

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
41

rùa. đóng dấu[]

Đóng dấu một bản sao của hình con rùa lên canvas ở vị trí con rùa hiện tại. Trả lại một tem_id cho tem đó, có thể được sử dụng để xóa nó bằng cách gọi

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1236

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
42

rùa. dấu xóa[dấu]

Stampid – một số nguyên, phải là giá trị trả về của lệnh gọi

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
429 trước đó

Xóa tem với tem đã cho

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
43

rùa. dấu xóa[n=Không]¶Parameters

n – một số nguyên [hoặc

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229]

Xóa tất cả hoặc n tem đầu tiên/cuối cùng của rùa. Nếu n là

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, xóa tất cả tem, nếu n > 0 xóa n tem đầu tiên, ngược lại nếu n < 0 xóa n tem cuối cùng

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
44

rùa. hoàn tác[]

Hoàn tác [nhiều lần] [các] hành động rùa cuối cùng. Số lượng hành động hoàn tác khả dụng được xác định bởi kích thước của bộ đệm hoàn tác

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
45

rùa. tốc độ[tốc độ=Không]¶Parameters

tốc độ – một số nguyên trong phạm vi 0. 10 hoặc dây tốc độ [xem bên dưới]

Đặt tốc độ của rùa thành một giá trị nguyên trong phạm vi 0. 10. Nếu không có đối số nào được đưa ra, hãy trả về tốc độ hiện tại

Nếu đầu vào là một số lớn hơn 10 hoặc nhỏ hơn 0. 5, tốc độ được đặt thành 0. Dây tốc độ được ánh xạ tới các giá trị tốc độ như sau

  • “nhanh nhất”. 0

  • "Nhanh". 10

  • "thông thường". 6

  • "chậm". 3

  • “chậm nhất”. 1

Tốc độ từ 1 đến 10 thực thi hoạt ảnh vẽ đường thẳng và xoay rùa ngày càng nhanh hơn

Chú ý. tốc độ = 0 có nghĩa là không có hoạt ảnh nào diễn ra. tiến/lùi khiến rùa nhảy và tương tự trái/phải khiến rùa quay ngay lập tức

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
46

Cho biết trạng thái của Rùa¶

rùa. vị trí[]rùa. tư thế[]

Trả về vị trí hiện tại của con rùa [x,y] [dưới dạng vectơ

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1231]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
47

rùa. về phía[x , y=None]¶Parameters
  • x – một số hoặc một cặp/vec-tơ số hoặc một cá thể rùa

  • y – một số nếu x là một số, nếu không thì

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229

Trả lại góc giữa đường từ vị trí con rùa đến vị trí được chỉ định bởi [x,y], vectơ hoặc con rùa khác. Điều này phụ thuộc vào hướng bắt đầu của rùa, tùy thuộc vào chế độ - “tiêu chuẩn”/”thế giới” hoặc “logo”

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
48

rùa. xcor[]

Trả về tọa độ x của con rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
49

rùa. ycor[]

Trả về tọa độ y của rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
120

rùa. tiêu đề[]

Trả về tiêu đề hiện tại của rùa [giá trị tùy thuộc vào chế độ rùa, xem

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1207]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
121

rùa. khoảng cách[x , y=None]¶Parameters
  • x – một số hoặc một cặp/vec-tơ số hoặc một cá thể rùa

  • y – một số nếu x là một số, nếu không thì

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229

Trả về khoảng cách từ con rùa đến [x,y], vectơ đã cho hoặc con rùa đã cho khác, theo đơn vị bước rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
122

Cài đặt đo lường¶

rùa. độ[vòng tròn=360. 0] ¶Thông số

hình tròn – một số

Đặt đơn vị đo góc i. e. đặt số "độ" cho một vòng tròn đầy đủ. Giá trị mặc định là 360 độ

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
123

rùa. radian[]

Đặt đơn vị đo góc thành radian. Tương đương với

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1244

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
124

Điều khiển bút¶

Trạng thái bản vẽ¶

rùa. phập[]rùa. pd[]rùa. xuống[]

Kéo bút xuống – vẽ khi di chuyển

rùa. penup[]turtle. pu[]turtle. up[]

Pull the pen up – no drawing when moving

turtle. kích thước[chiều rộng=Không có . ]turtle.chiều rộng[chiều rộng=Không có]¶Parameters

width – a positive number

Đặt độ dày của đường thành chiều rộng hoặc trả lại. Nếu chế độ thay đổi kích thước được đặt thành “tự động” và hình con rùa là một đa giác, thì đa giác đó được vẽ với cùng độ dày nét vẽ. If no argument is given, the current pensize is returned

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
125

turtle. bút[bút=Không có, **pendict]¶Parameters
  • pen – a dictionary with some or all of the below listed keys

  • pendict – one or more keyword-arguments with the below listed keys as keywords

Trả lại hoặc đặt các thuộc tính của bút trong “từ điển bút” với các cặp khóa/giá trị sau

  • “shown”. True/False

  • "đặt bút xuống". True/False

  • “màu bút”. color-string or color-tuple

  • “fillcolor”. color-string or color-tuple

  • “bù”. positive number

  • “speed”. số trong phạm vi 0. 10

  • "chế độ thay đổi kích thước". “auto” or “user” or “noresize”

  • "máy kéo dài". [positive number, positive number]

  • “outline”. positive number

  • “nghiêng”. number

This dictionary can be used as argument for a subsequent call to

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
451 to restore the former pen-state. Moreover one or more of these attributes can be provided as keyword-arguments. This can be used to set several pen attributes in one statement

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
126

turtle. isdown[]

Return

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1246 if pen is down,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1247 if it’s up

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
127

Color control¶

rùa. pencolor[*args]

Return or set the pencolor

Four input formats are allowed

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
454

Return the current pencolor as color specification string or as a tuple [see example]. May be used as input to another color/pencolor/fillcolor call

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1249

Đặt pencolor thành chuỗi màu, là chuỗi đặc tả màu Tk, chẳng hạn như

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1250,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1251 hoặc
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1252

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1253

Đặt pencolor thành màu RGB được biểu thị bằng bộ của r, g và b. Mỗi r, g và b phải nằm trong phạm vi 0. colormode, where colormode is either 1. 0 or 255 [see

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1208]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1255

Set pencolor to the RGB color represented by r, g, and b. Mỗi r, g và b phải nằm trong phạm vi 0. chế độ màu

Nếu hình con rùa là một đa giác, thì đường viền của đa giác đó được vẽ bằng bút màu mới được đặt

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
128

rùa. màu tô[*args]

Trả lại hoặc đặt màu tô

Four input formats are allowed

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
455

Return the current fillcolor as color specification string, possibly in tuple format [see example]. Có thể được sử dụng làm đầu vào cho lệnh gọi color/pencolor/fillcolor khác

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1257

Đặt màu tô thành chuỗi màu, là chuỗi đặc tả màu Tk, chẳng hạn như

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1250,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1251 hoặc
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1252

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1261

Set fillcolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0. colormode, where colormode is either 1. 0 or 255 [see

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1208]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1263

Set fillcolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0. colormode

If turtleshape is a polygon, the interior of that polygon is drawn with the newly set fillcolor

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
129

rùa. color[*args]

Return or set pencolor and fillcolor

Một số định dạng đầu vào được cho phép. Họ sử dụng 0 đến 3 đối số như sau

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
453

Trả về màu bút hiện tại và màu tô hiện tại dưới dạng một cặp chuỗi hoặc bộ đặc tả màu như được trả về bởi

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
454 và
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
455

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1267,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1268,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1269

Đầu vào như trong

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
454, đặt cả hai, màu tô và màu bút, thành giá trị đã cho

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1271,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1272

Equivalent to

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1273 and
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1274 and analogously if the other input format is used

If turtleshape is a polygon, outline and interior of that polygon is drawn with the newly set colors

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
400

See also. Screen method

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1208

Filling¶

turtle. filling[]

Return fillstate [

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1246 if filling,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1247 else]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
401

turtle. begin_fill[]

To be called just before drawing a shape to be filled

turtle. end_fill[]

Fill the shape drawn after the last call to

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
457

Whether or not overlap regions for self-intersecting polygons or multiple shapes are filled depends on the operating system graphics, type of overlap, and number of overlaps. Ví dụ: ngôi sao Rùa ở trên có thể toàn màu vàng hoặc có một số vùng màu trắng

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
402

More drawing control¶

turtle. reset[]

Delete the turtle’s drawings from the screen, re-center the turtle and set variables to the default values

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
403

turtle. xóa[]

Delete the turtle’s drawings from the screen. Do not move turtle. State and position of the turtle as well as drawings of other turtles are not affected

turtle. write[arg , move=False , align='left' , font=['Arial', 8, 'normal']] ¶Parameters
  • arg – object to be written to the TurtleScreen

  • move – True/False

  • align – one of the strings “left”, “center” or right”

  • font – a triple [fontname, fontsize, fonttype]

Viết văn bản - biểu diễn chuỗi của arg - tại vị trí con rùa hiện tại theo căn chỉnh [“trái”, “giữa” hoặc “phải”] và với phông chữ đã cho. If move is true, the pen is moved to the bottom-right corner of the text. By default, move is

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1247

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
404

Turtle state¶

Visibility¶

turtle. hideturtle[]turtle. ht[]

Làm cho con rùa vô hình. Bạn nên làm điều này khi đang thực hiện một số bản vẽ phức tạp, bởi vì việc ẩn con rùa sẽ tăng tốc độ vẽ một cách đáng kể

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
405

turtle. showturtle[]turtle. st[]

Make the turtle visible

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
406

turtle. isvisible[]

Return

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1246 if the Turtle is shown,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1247 if it’s hidden

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
407

Appearance¶

rùa. hình dạng[tên=Không có]¶Parameters

name – a string which is a valid shapename

Set turtle shape to shape with given name or, if name is not given, return name of current shape. Hình dạng có tên phải tồn tại trong từ điển hình dạng của TurtleScreen. Initially there are the following polygon shapes. “arrow”, “turtle”, “circle”, “square”, “triangle”, “classic”. To learn about how to deal with shapes see Screen method

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1211

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
408

turtle. resizemode[rmode=None] ¶Parameters

rmode – one of the strings “auto”, “user”, “noresize”

Set resizemode to one of the values. “auto”, “user”, “noresize”. Nếu rmode không được cung cấp, hãy trả về resizemode hiện tại. Different resizemodes have the following effects

  • “auto”. điều chỉnh sự xuất hiện của con rùa tương ứng với giá trị của pensize

  • “user”. adapts the appearance of the turtle according to the values of stretchfactor and outlinewidth [outline], which are set by

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    469

  • “noresize”. no adaption of the turtle’s appearance takes place

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1284 is called by
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
469 when used with arguments

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
409

turtle. shapesize[stretch_wid=None , stretch_len=None , outline=None]turtle. turtlesize[stretch_wid=None , stretch_len=None , outline=None] ¶Parameters
  • stretch_wid – positive number

  • stretch_len – positive number

  • outline – positive number

Return or set the pen’s attributes x/y-stretchfactors and/or outline. Set resizemode to “user”. If and only if resizemode is set to “user”, the turtle will be displayed stretched according to its stretchfactors. stretch_wid is stretchfactor perpendicular to its orientation, stretch_len is stretchfactor in direction of its orientation, outline determines the width of the shapes’s outline

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
440

turtle. shearfactor[shear=None] ¶Parameters

shear – number [optional]

Set or return the current shearfactor. Shear the turtleshape according to the given shearfactor shear, which is the tangent of the shear angle. Do not change the turtle’s heading [direction of movement]. Nếu cắt không được đưa ra. return the current shearfactor, i. e. the tangent of the shear angle, by which lines parallel to the heading of the turtle are sheared

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
441

turtle. tilt[angle] ¶Parameters

angle – a number

Rotate the turtleshape by angle from its current tilt-angle, but do not change the turtle’s heading [direction of movement]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
442

turtle. settiltangle[angle] ¶Parameters

angle – a number

Xoay hình con rùa để chỉ theo hướng được chỉ định theo góc, bất kể góc nghiêng hiện tại của nó là gì. Do not change the turtle’s heading [direction of movement]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
443

Deprecated since version 3. 1

turtle. tiltangle[angle=None] ¶Parameters

angle – a number [optional]

Set or return the current tilt-angle. Nếu góc được đưa ra, hãy xoay hình con rùa để chỉ theo hướng được chỉ định bởi góc, bất kể góc nghiêng hiện tại của nó là gì. Do not change the turtle’s heading [direction of movement]. If angle is not given. return the current tilt-angle, i. e. the angle between the orientation of the turtleshape and the heading of the turtle [its direction of movement]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
444

rùa. shapetransform[t11=Không, t12=None, t21=None, t22=None]¶Parameters
  • t11 – một số [tùy chọn]

  • t12 – một số [tùy chọn]

  • t21 – một số [tùy chọn]

  • t12 – một số [tùy chọn]

Đặt hoặc trả về ma trận biến đổi hiện tại của hình con rùa

Nếu không có phần tử nào của ma trận được đưa ra, hãy trả về ma trận biến đổi dưới dạng một bộ gồm 4 phần tử. Mặt khác, đặt các phần tử đã cho và biến đổi hình con rùa theo ma trận bao gồm hàng đầu tiên t11, t12 và hàng thứ hai t21, t22. Định thức t11 * t22 - t12 * t21 không được bằng 0, nếu không sẽ xảy ra lỗi. Modify stretchfactor, shearfactor and tiltangle according to the given matrix

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
445

rùa. get_shapepoly[]

Return the current shape polygon as tuple of coordinate pairs. Điều này có thể được sử dụng để xác định một hình dạng mới hoặc các thành phần của một hình dạng ghép

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
446

Sử dụng sự kiện¶

rùa. title[vui , btn=1, add=None]Parameters
  • fun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ

  • btn – số nút chuột, mặc định là 1 [nút chuột trái]

  • thêm –

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246 hoặc
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1247 – nếu là
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ

Liên kết thú vị với các sự kiện nhấp chuột trên con rùa này. Nếu niềm vui là

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, các ràng buộc hiện có sẽ bị xóa. Ví dụ cho con rùa vô danh, tôi. e. cách thủ tục

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
447

rùa. ra mắt[vui , btn=1, add=None]¶Parameters
  • fun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ

  • btn – số nút chuột, mặc định là 1 [nút chuột trái]

  • thêm –

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246 hoặc
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1247 – nếu là
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ

Liên kết thú vị với các sự kiện nhả nút chuột trên con rùa này. Nếu niềm vui là

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, các ràng buộc hiện có sẽ bị xóa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
448

rùa. ondrag[vui , btn=1, add=None]¶Parameters
  • fun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ

  • btn – số nút chuột, mặc định là 1 [nút chuột trái]

  • thêm –

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246 hoặc
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1247 – nếu là
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ

Liên kết các sự kiện di chuyển chuột thú vị trên con rùa này. Nếu niềm vui là

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, các ràng buộc hiện có sẽ bị xóa

Nhận xét. Mỗi chuỗi sự kiện di chuyển chuột trên một con rùa được bắt đầu bằng một sự kiện nhấp chuột trên con rùa đó

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
449

Sau đó, nhấp và kéo Rùa sẽ di chuyển nó trên màn hình do đó tạo ra các hình vẽ tay [nếu bút bị hỏng]

Phương pháp rùa đặc biệt¶

rùa. begin_poly[]

Bắt đầu ghi các đỉnh của một đa giác. Vị trí con rùa hiện tại là đỉnh đầu tiên của đa giác

rùa. end_poly[]

Dừng ghi các đỉnh của một đa giác. Vị trí con rùa hiện tại là đỉnh cuối cùng của đa giác. Điều này sẽ được kết nối với đỉnh đầu tiên

rùa. get_poly[]

Trả lại đa giác được ghi cuối cùng

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
490

rùa. nhân bản[]

Tạo và trả về một bản sao của con rùa với cùng vị trí, tiêu đề và thuộc tính của con rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
491

rùa. con rùa[]con rùa. getpen[]

Trả lại chính đối tượng Rùa. Chỉ sử dụng hợp lý. như một chức năng để trả về "rùa ẩn danh"

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
492

rùa. nhận màn hình[]

Trả lại đối tượng

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
5 mà con rùa đang vẽ. Các phương thức TurtleScreen sau đó có thể được gọi cho đối tượng đó

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
493

rùa. setundobuffer[kích thước]

size – một số nguyên hoặc

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229

Đặt hoặc vô hiệu hóa bộ đệm. Nếu kích thước là một số nguyên, một bộ hoàn tác trống có kích thước đã cho sẽ được cài đặt. size đưa ra số lượng hành động rùa tối đa có thể hoàn tác bằng phương thức/hàm

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
432. Nếu kích thước là
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, bộ hoàn tác bị vô hiệu hóa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
494

rùa. các mục hoàn tác bộ đệm[]

Trả về số mục nhập trong bộ hoàn tác

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
495

Các hình ghép¶

Để sử dụng các hình con rùa phức hợp, bao gồm một số đa giác có màu khác nhau, bạn phải sử dụng lớp trợ giúp

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4002 một cách rõ ràng như được mô tả bên dưới

  1. Tạo một đối tượng Shape rỗng kiểu “compound”

  2. Thêm bao nhiêu thành phần vào đối tượng này nếu muốn, sử dụng phương thức

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4003

    Ví dụ

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    496

  3. Bây giờ hãy thêm Hình dạng vào danh sách hình dạng của Màn hình và sử dụng nó

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    497

Ghi chú

Lớp

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4002 được sử dụng nội bộ bởi phương thức
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1211 theo nhiều cách khác nhau. Người lập trình ứng dụng chỉ phải xử lý lớp Hình dạng khi sử dụng các hình dạng phức hợp như được hiển thị ở trên

Các phương thức của TurtleScreen/Screen và các chức năng tương ứng¶

Hầu hết các ví dụ trong phần này đề cập đến một phiên bản TurtleScreen có tên là

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4006

Điều khiển cửa sổ¶

rùa. bgcolor[*args]¶Parameters

args – một chuỗi màu hoặc ba số trong phạm vi 0. colormode hoặc một bộ 3 số như vậy

Đặt hoặc trả về màu nền của TurtleScreen

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
498

rùa. bgpic[picname=Không có]¶Parameters

picname – một chuỗi, tên của tệp gif hoặc

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4007 hoặc
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229

Đặt hình nền hoặc trả về tên của hình nền hiện tại. Nếu picname là tên tệp, hãy đặt hình ảnh tương ứng làm nền. If picname is

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4007, delete background image, if present. If picname is
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, return the filename of the current backgroundimage

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
499

turtle. xóa[]

Ghi chú

This TurtleScreen method is available as a global function only under the name

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4011. The global function
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4012 is a different one derived from the Turtle method
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4012

turtle. clearscreen[]

Delete all drawings and all turtles from the TurtleScreen. Reset the now empty TurtleScreen to its initial state. white background, no background image, no event bindings and tracing on

turtle. reset[]

Ghi chú

This TurtleScreen method is available as a global function only under the name

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4014. The global function
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4015 is another one derived from the Turtle method
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4015

turtle. resetscreen[]

Reset all Turtles on the Screen to their initial state

turtle. screensize[canvwidth=None , canvheight=None , bg=None] ¶Parameters
  • canvwidth – positive integer, new width of canvas in pixels

  • canvheight – positive integer, new height of canvas in pixels

  • bg – chuỗi màu hoặc bộ màu, màu nền mới

Nếu không có đối số nào được đưa ra, hãy trả về giá trị hiện tại [canvaswidth, canvasheight]. Khác thay đổi kích thước canvas mà rùa đang vẽ trên đó. Không thay đổi cửa sổ bản vẽ. Để quan sát các phần ẩn của canvas, hãy sử dụng thanh cuộn. Với phương pháp này, người ta có thể hiển thị các phần của bản vẽ nằm ngoài canvas trước đó.

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
500

e. g. để tìm kiếm một con rùa trốn thoát nhầm ;-]

rùa. tọa độ setworld[llx , lly, urx, ury]¶Parameters
  • llx – một số, tọa độ x của góc dưới bên trái của canvas

  • lly – một số, tọa độ y của góc dưới bên trái của canvas

  • urx – một số, tọa độ x của góc trên bên phải của canvas

  • ury – một số, tọa độ y của góc trên bên phải của canvas

Thiết lập hệ tọa độ do người dùng định nghĩa và chuyển sang chế độ “thế giới” nếu cần. Điều này thực hiện một

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4017. Nếu chế độ “thế giới” đã hoạt động, tất cả các bản vẽ được vẽ lại theo tọa độ mới

CHÚ Ý. trong các góc của hệ tọa độ do người dùng xác định có thể bị biến dạng

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
501

Điều khiển hoạt ảnh¶

rùa. delay[delay=None] ¶Parameters

delay – positive integer

Set or return the drawing delay in milliseconds. [This is approximately the time interval between two consecutive canvas updates. ] The longer the drawing delay, the slower the animation

Optional argument

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
502

turtle. tracer[n=None , delay=None] ¶Parameters
  • n – nonnegative integer

  • delay – nonnegative integer

Turn turtle animation on/off and set delay for update drawings. If n is given, only each n-th regular screen update is really performed. [Can be used to accelerate the drawing of complex graphics. ] When called without arguments, returns the currently stored value of n. Second argument sets delay value [see

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
495]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
503

turtle. update[]

Perform a TurtleScreen update. To be used when tracer is turned off

See also the RawTurtle/Turtle method

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
433

Using screen events¶

turtle. listen[xdummy=None , ydummy=None]

Set focus on TurtleScreen [in order to collect key-events]. Dummy arguments are provided in order to be able to pass

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
498 to the title method

turtle. onkey[fun , key]turtle. onkeyrelease[fun , key] ¶Parameters
  • fun – a function with no arguments or

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229

  • key – a string. key [e. g. “a”] or key-symbol [e. g. “space”]

Bind fun to key-release event of key. If fun is

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, event bindings are removed. Remark. in order to be able to register key-events, TurtleScreen must have the focus. [See method
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
498. ]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
504

turtle. onkeypress[fun , key=None] ¶Parameters
  • fun – a function with no arguments or

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229

  • key – a string. key [e. g. “a”] or key-symbol [e. g. “space”]

Bind fun to key-press event of key if key is given, or to any key-press-event if no key is given. Remark. in order to be able to register key-events, TurtleScreen must have focus. [See method

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
498. ]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
505

turtle. title[fun , btn=1 , add=None]turtle. onscreenclick[fun , btn=1 , add=None] ¶Parameters
  • fun – một hàm có hai đối số sẽ được gọi với tọa độ của điểm được nhấp trên khung vẽ

  • btn – số nút chuột, mặc định là 1 [nút chuột trái]

  • thêm –

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246 hoặc
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1247 – nếu là
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246, một ràng buộc mới sẽ được thêm vào, nếu không nó sẽ thay thế một ràng buộc cũ

Bind fun to mouse-click events on this screen. If fun is

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229, existing bindings are removed

Example for a TurtleScreen instance named

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4006 and a Turtle instance named
>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
8

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
506

Ghi chú

This TurtleScreen method is available as a global function only under the name

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4032. Hàm toàn cục
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4033 là một hàm khác bắt nguồn từ phương thức Rùa
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4033

turtle. ontimer[fun , t=0] ¶Parameters
  • fun – a function with no arguments

  • t – a number >= 0

Install a timer that calls fun after t milliseconds

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
507

rùa. vòng lặp chính[]rùa. done[]

Starts event loop - calling Tkinter’s mainloop function. Must be the last statement in a turtle graphics program. Must not be used if a script is run from within IDLE in -n mode [No subprocess] - for interactive use of turtle graphics

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
508

Input methods¶

turtle. textinput[title , prompt] ¶Parameters
  • title – string

  • prompt – string

Pop up a dialog window for input of a string. Parameter title is the title of the dialog window, prompt is a text mostly describing what information to input. Return the string input. If the dialog is canceled, return

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
509

turtle. numinput[title , prompt , default=None , minval=None , maxval=None] ¶Parameters
  • title – string

  • prompt – string

  • default – number [optional]

  • minval – number [optional]

  • maxval – number [optional]

Pop up a dialog window for input of a number. title is the title of the dialog window, prompt is a text mostly describing what numerical information to input. default. default value, minval. minimum value for input, maxval. maximum value for input. The number input must be in the range minval . maxval if these are given. If not, a hint is issued and the dialog remains open for correction. Return the number input. If the dialog is canceled, return

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
510

Settings and special methods¶

turtle. mode[mode=None] ¶Parameters

mode – one of the strings “standard”, “logo” or “world”

Set turtle mode [“standard”, “logo” or “world”] and perform reset. If mode is not given, current mode is returned

Mode “standard” is compatible with old

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
8. Mode “logo” is compatible with most Logo turtle graphics. Mode “world” uses user-defined “world coordinates”. Attention. in this mode angles appear distorted if
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4038 unit-ratio doesn’t equal 1

Mode

Initial turtle heading

positive angles

“standard”

to the right [east]

counterclockwise

“logo”

upward [north]

clockwise

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
511

turtle. colormode[cmode=None] ¶Parameters

cmode – one of the values 1. 0 or 255

Return the colormode or set it to 1. 0 or 255. Subsequently r, g, b values of color triples have to be in the range 0. *cmode*

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
512

turtle. getcanvas[]

Trả lại Canvas của TurtleScreen này. Useful for insiders who know what to do with a Tkinter Canvas

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
513

turtle. getshapes[]

Return a list of names of all currently available turtle shapes

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
514

turtle. register_shape[name , shape=None]turtle. addshape[name , shape=None]

Có ba cách khác nhau để gọi chức năng này

  1. tên là tên của tệp gif và hình dạng là

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229. Cài đặt hình ảnh tương ứng

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    515

    Ghi chú

    Các hình ảnh không xoay khi xoay rùa nên không hiển thị tiêu đề của rùa

  2. tên là một chuỗi tùy ý và hình dạng là một bộ các cặp tọa độ. Cài đặt hình đa giác tương ứng

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    516

  3. tên là một chuỗi tùy ý và hình dạng là một đối tượng [hợp chất]

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4002. Install the corresponding compound shape

Add a turtle shape to TurtleScreen’s shapelist. Only thusly registered shapes can be used by issuing the command

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4041

turtle. turtles[]

Return the list of turtles on the screen

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
517

turtle. window_height[]

Return the height of the turtle window

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
518

turtle. window_width[]

Return the width of the turtle window

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
519

Methods specific to Screen, not inherited from TurtleScreen¶

turtle. bye[]

Shut the turtlegraphics window

turtle. exit title[]

Bind

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1218 method to mouse clicks on the Screen

If the value “using_IDLE” in the configuration dictionary is

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1247 [default value], also enter mainloop. Remark. If IDLE with the
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
3 switch [no subprocess] is used, this value should be set to
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1246 in
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4046. In this case IDLE’s own mainloop is active also for the client script

turtle. setup[width=_CFG['width'] , height=_CFG['height'] , startx=_CFG['leftright'] , starty=_CFG['topbottom']]

Set the size and position of the main window. Default values of arguments are stored in the configuration dictionary and can be changed via a

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4046 file

Parameters
  • width – if an integer, a size in pixels, if a float, a fraction of the screen; default is 50% of screen

  • height – if an integer, the height in pixels, if a float, a fraction of the screen; default is 75% of screen

  • startx – if positive, starting position in pixels from the left edge of the screen, if negative from the right edge, if

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229, center window horizontally

  • starty – if positive, starting position in pixels from the top edge of the screen, if negative from the bottom edge, if

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1229, center window vertically

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
0

turtle. title[titlestring] ¶Parameters

titlestring – a string that is shown in the titlebar of the turtle graphics window

Set title of turtle window to titlestring

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
1

Public classes¶

class turtle. RawTurtle[canvas]class turtle. RawPen[canvas] ¶Parameters

canvas – a

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
6, a
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
7 or a
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
5

Tạo một con rùa. The turtle has all methods described above as “methods of Turtle/RawTurtle”

class turtle. Turtle

Subclass of RawTurtle, has the same interface but draws on a default

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
407 object created automatically when needed for the first time

class turtle. TurtleScreen[cv] ¶Parameters

cv – a

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
6

Provides screen oriented methods like

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4055 etc. that are described above

class turtle. Screen

Subclass of TurtleScreen, with four methods added .

class turtle. ScrolledCanvas[master] ¶Parameters

master – some Tkinter widget to contain the ScrolledCanvas, i. e. a Tkinter-canvas with scrollbars added

Used by class Screen, which thus automatically provides a ScrolledCanvas as playground for the turtles

class turtle. Shape[type_ , data] ¶Parameters

type_ – one of the strings “polygon”, “image”, “compound”

Data structure modeling shapes. The pair

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4056 must follow this specification

type_

data

“polygon”

a polygon-tuple, i. e. a tuple of pairs of coordinates

“image”

an image [in this form only used internally. ]

“compound”

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1229 [a compound shape has to be constructed using the
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4003 method]

addcomponent[poly , fill , outline=None] ¶Parameters
  • poly – a polygon, i. e. a tuple of pairs of numbers

  • fill – a color the poly will be filled with

  • outline – a color for the poly’s outline [if given]

Example

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
2

See Compound shapes .

class turtle. Vec2D[x , y]

A two-dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs too. Derived from tuple, so a vector is a tuple

Provides [for a, b vectors, k number]

  • >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4059 vector addition

  • >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4060 vector subtraction

  • >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4061 inner product

  • >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4062 and
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4063 multiplication with scalar

  • >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4064 absolute value of a

  • >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4065 rotation

Trợ giúp và cấu hình¶

Cách sử dụng trợ giúp¶

Các phương thức công khai của các lớp Màn hình và Rùa được ghi lại rộng rãi thông qua các tài liệu. Vì vậy, chúng có thể được sử dụng làm trợ giúp trực tuyến thông qua các tiện ích trợ giúp của Python

  • Khi sử dụng IDLE, chú giải công cụ hiển thị chữ ký và dòng đầu tiên của chuỗi tài liệu được nhập trong lệnh gọi hàm/phương thức

  • Gọi

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4066 trên các phương thức hoặc chức năng sẽ hiển thị các chuỗi tài liệu

    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    3

  • Các tài liệu của các chức năng bắt nguồn từ các phương thức có dạng được sửa đổi

    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    4

Các chuỗi tài liệu đã sửa đổi này được tạo tự động cùng với các định nghĩa hàm bắt nguồn từ các phương thức tại thời điểm nhập

Dịch tài liệu sang các ngôn ngữ khác nhau¶

Có một tiện ích để tạo một từ điển, các khóa là tên phương thức và giá trị của chúng là chuỗi tài liệu của các phương thức công khai của các lớp Màn hình và Con rùa

rùa. write_docstringdict[tên tệp=']¶Parameters

tên tệp - một chuỗi, được sử dụng làm tên tệp

Tạo và viết từ điển chuỗi tài liệu vào tập lệnh Python với tên tệp đã cho. Chức năng này phải được gọi rõ ràng [nó không được sử dụng bởi các lớp đồ họa con rùa]. Từ điển chuỗi tài liệu sẽ được ghi vào tập lệnh Python

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4067. Nó được dùng làm khuôn mẫu để dịch các chuỗi tài liệu sang các ngôn ngữ khác nhau

Nếu bạn [hoặc học sinh của bạn] muốn sử dụng

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
8 với trợ giúp trực tuyến bằng ngôn ngữ mẹ đẻ của mình, bạn phải dịch các chuỗi tài liệu và lưu tệp kết quả dưới dạng e. g.
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4069

Nếu bạn có một mục thích hợp trong tệp

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4046 của mình, từ điển này sẽ được đọc tại thời điểm nhập và sẽ thay thế các chuỗi tài liệu gốc bằng tiếng Anh

Tại thời điểm viết bài này, có các từ điển chuỗi tài liệu bằng tiếng Đức và tiếng Ý. [Các yêu cầu vui lòng tham khảo @ aon . tại. ]

Cách định cấu hình Màn hình và Rùa¶

Cấu hình mặc định tích hợp bắt chước giao diện và hành vi của mô-đun rùa cũ để duy trì khả năng tương thích tốt nhất có thể với nó

Nếu bạn muốn sử dụng một cấu hình khác phản ánh tốt hơn các tính năng của mô-đun này hoặc phù hợp hơn với nhu cầu của bạn, hãy. g. để sử dụng trong lớp học, bạn có thể chuẩn bị tệp cấu hình

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4046 sẽ được đọc tại thời điểm nhập và sửa đổi cấu hình theo cài đặt của nó

Cấu hình tích hợp sẽ tương ứng với con rùa sau. cfg

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
5

Giải thích ngắn về các mục đã chọn

  • Bốn dòng đầu tiên tương ứng với các đối số của phương thức

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4072

  • Dòng 5 và 6 tương ứng với các đối số của phương thức

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4073

  • hình dạng có thể là bất kỳ hình dạng tích hợp nào, e. g. mũi tên, rùa, vv. Để biết thêm thông tin, hãy thử

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4074

  • Nếu bạn muốn sử dụng không tô màu [tôi. e. làm cho con rùa trong suốt], bạn phải viết

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4075 [nhưng tất cả các chuỗi không trống không được có dấu ngoặc kép trong tệp cfg]

  • Nếu bạn muốn phản ánh trạng thái của rùa, bạn phải sử dụng

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4076

  • Nếu bạn đặt e. g.

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4077 docstringdict
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4078 sẽ được tải vào thời điểm nhập [nếu xuất hiện trên đường dẫn nhập, e. g. trong cùng thư mục với
    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    8]

  • Các mục exampleturtle và examplescreen xác định tên của các đối tượng này khi chúng xuất hiện trong chuỗi tài liệu. Việc chuyển đổi method-docstrings thành function-docstrings sẽ xóa những tên này khỏi docstrings

  • sử dụng_IDLE. Đặt giá trị này thành

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246 nếu bạn thường xuyên làm việc với IDLE và công tắc
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    3 của nó [“không có quy trình con”]. Điều này sẽ ngăn
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1219 vào vòng lặp chính

Có thể có một tệp

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4046 trong thư mục lưu trữ
>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
8 và một tệp bổ sung trong thư mục làm việc hiện tại. Cái sau sẽ ghi đè cài đặt của cái đầu tiên

Thư mục

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4085 chứa tệp
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4046. Bạn có thể nghiên cứu nó như một ví dụ và xem tác dụng của nó khi chạy các bản demo [tốt nhất là không phải từ bên trong trình xem bản demo]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4087 — Tập lệnh demo¶

Gói

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4087 bao gồm một tập lệnh demo. Có thể chạy và xem các tập lệnh này bằng trình xem demo được cung cấp như sau

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
6

Ngoài ra, bạn có thể chạy các tập lệnh demo riêng lẻ. Ví dụ,

>>> turtle.setheading[90]
>>> turtle.heading[]
90.0
7

Thư mục gói

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
4087 chứa

  • Trình xem demo ________ 14090 có thể được sử dụng để xem mã nguồn của các tập lệnh và chạy chúng cùng một lúc

  • Nhiều tập lệnh thể hiện các tính năng khác nhau của mô-đun

    >>> turtle.setheading[90]
    >>> turtle.heading[]
    90.0
    
    8. Các ví dụ có thể được truy cập thông qua menu Ví dụ. Chúng cũng có thể được chạy độc lập

  • Tệp

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4046 dùng làm ví dụ về cách viết và sử dụng các tệp đó

Các kịch bản demo là

Tên

Sự miêu tả

Đặc trưng

thiết kế phụ

mô hình đồ họa rùa cổ điển phức tạp

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
496, trì hoãn,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
497

sự hỗn loạn

biểu đồ động lực học Verhulst, cho thấy rằng các tính toán của máy tính đôi khi có thể tạo ra kết quả trái với mong đợi thông thường

tọa độ thế giới

cái đồng hồ

đồng hồ analog hiển thị thời gian của máy tính của bạn

rùa như kim đồng hồ, hẹn giờ

máy pha màu

thử nghiệm với r, g, b

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
479

rừng

3 cây theo chiều rộng

ngẫu nhiên hóa

đường cong fractal

Đường cong Hilbert & Koch

đệ quy

cây bồ đề

dân tộc học [kolams Ấn Độ]

Hệ thống chữ L

min_hanoi

Tháp Hà Nội

Rùa Chữ Nhật dạng đĩa Hà Nội [hình dáng, kích thước]

nim

chơi game nim cổ điển với ba đống gậy trên máy tính

rùa như nimsticks, điều khiển sự kiện [chuột, bàn phím]

Sơn

chương trình vẽ siêu tối giản

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
477

hòa bình

tiểu học

rùa. xuất hiện và hoạt hình

hoa hồng

lát gạch định kỳ với diều và phi tiêu

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
429

hành_tinh_và_mặt_trăng

mô phỏng hệ trọng lực

hình ghép,

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
1231

round_dance

rùa nhảy múa quay theo cặp theo hướng ngược lại

hình ghép, nhân bản shapesize, tilt, get_shapepoly, cập nhật

sorting_animate

trình diễn trực quan các phương pháp sắp xếp khác nhau

căn chỉnh đơn giản, ngẫu nhiên

cây

cây đầu tiên có chiều rộng [đồ họa] [sử dụng trình tạo]

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
483

two_canvases

Thiết kế đơn giản

rùa trên hai bức tranh

wikipedia

một mẫu từ bài viết trên wikipedia về đồ họa con rùa

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
483,
>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
432

yinyang

một ví dụ cơ bản khác

>>> turtle.heading[]
90.0
>>> turtle.position[]
[0.00,-10.00]
>>> turtle.home[]
>>> turtle.position[]
[0.00,0.00]
>>> turtle.heading[]
0.0
427

Chúc vui vẻ

Những thay đổi kể từ Python 2. 6¶

  • Các phương thức

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4403,
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4404 và
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4405 đã bị loại bỏ. Các phương thức có các tên và chức năng này hiện chỉ khả dụng dưới dạng các phương thức của
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    407. Các chức năng bắt nguồn từ những vẫn có sẵn. [Thực tế đã có trong Python 2. 6 các phương thức này chỉ đơn thuần là bản sao của các phương thức
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    5/
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    407 tương ứng. ]

  • Phương pháp

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4409 đã bị loại bỏ. Hành vi của
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    457 và
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    458 đã thay đổi một chút. bây giờ mọi quy trình điền phải được hoàn thành bằng lệnh gọi
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    458

  • Một phương pháp

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4413 đã được thêm vào. Nó trả về một giá trị boolean.
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1246 nếu quy trình chiết rót đang được tiến hành, nếu không thì
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1247. Hành vi này tương ứng với lệnh gọi
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4416 không có đối số trong Python 2. 6

Các thay đổi kể từ Python 3. 0¶

  • Các phương pháp

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4417,
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4418 và
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4419 đã được thêm vào. Do đó, hiện có đầy đủ các phép biến đổi tuyến tính thông thường để biến đổi hình con rùa.
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4420 đã được tăng cường chức năng. bây giờ nó có thể được sử dụng để lấy hoặc đặt góc nghiêng.
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4421 không được dùng nữa

  • Phương thức

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4422 đã được thêm vào như một phần bổ sung cho
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4423, trên thực tế, phương thức này liên kết các hành động với sự kiện phát hành khóa. Theo đó, cái sau có bí danh.
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4424

  • Phương pháp

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4425 đã được thêm vào. Vì vậy, khi chỉ làm việc với các đối tượng Màn hình và Rùa, người ta không được nhập thêm
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    1205 nữa

  • Hai phương thức nhập liệu đã được thêm vào

    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4427 và
    >>> turtle.heading[]
    90.0
    >>> turtle.position[]
    [0.00,-10.00]
    >>> turtle.home[]
    >>> turtle.position[]
    [0.00,0.00]
    >>> turtle.heading[]
    0.0
    
    4428. Các hộp thoại đầu vào bật lên này và trả về các chuỗi và số tương ứng

    Chúng tôi có thể lấy thông tin đầu vào trong Python rùa không?

    numinput[] Hàm này dùng để bật cửa sổ hộp thoại nhập chuỗi. Trả lại đầu vào chuỗi.

    Onkeypress trong Python là gì?

    Mô-đun rùa của Python là một công cụ tuyệt vời để sử dụng cho việc dạy viết mã. Một trong những chức năng chính được sử dụng khi tạo hoạt ảnh hoặc trò chơi tương tác là onkeypress[] cho phép liên kết thao tác nhấn phím với chức năng .

Chủ Đề