Đồ 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.09, đư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.00, 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.01 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.08 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.03
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.04 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
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
>>> 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.0407 và
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0405. 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. Tất nhiên, các phương thức có đối số đầu tiên bổ sung self được bỏ qua ở đây
Tổng quan về các phương pháp Con rùa và Màn hình có sẵn¶
Phương pháp rùa¶
Chuyển động của rùa Di chuyển và vẽ>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0410.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0411
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0412.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0413.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0414
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0415 .
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0416
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0417.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0418
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0419.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0420.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0421
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0422
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0423
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0424.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0425
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0426
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0427
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0428
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0429
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0430
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0431
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0432
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0433Cho 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.0434.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0435
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0436
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0437
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0438
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0439
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0440Cài đặt và đo lường
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0441
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0442Đ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.0443.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0444.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0445
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0446.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0447.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0448
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0449.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0450
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0451
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0452Kiể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.0453
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0454
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0455đổ đầy
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0456
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0457
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0458Kiể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.0459
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0460
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0461Trạ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.0462.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0463
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0464.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0465
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0466Vẻ bề ngoài
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0467
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0468
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0469.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0470
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0471
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0472
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0473
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0474
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0475
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0476Sử 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.0477
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0478
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0479Phươ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.0480
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0481
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0482
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0483
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0484.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0485
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0486
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0487
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0488
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.0489
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0490
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0491
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0492
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0493
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0494kiể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.0495
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0496
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0497Sử 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.0498
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0499.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01200
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01201
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0477.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01203
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01204
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01205.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01206Cà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.01207
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01208
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01209
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01210
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01211.
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01212
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01213
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01214
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01215Phươ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.01216
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01217Cá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.01218
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01219
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01220
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01221
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.08
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.04rù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.012rù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.0441 và
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0442. ] Đị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.01207
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.040rù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.0441 và
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0442. ] Đị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.01207
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.044rù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.01229, 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.01231 [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.0435]
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.049rù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.050rù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.051rù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.0rù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.01207]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0rù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.040rù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.041rù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.01236
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.042rù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.0429 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.043turtle. 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.01229]
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.01229, 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.044rù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.045rù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. If no argument is given, return current speed
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.046
Cho biết trạng thái của Rùa¶
turtle. vị trí[] ¶ rùa. tư thế[] ¶Return the turtle’s current location [x,y] [as a
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01231 vector]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.047turtle. 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.048rù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.049rùa. ycor[] ¶
Return the turtle’s y coordinate
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0120rù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.01207]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0121rùa. distance[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.0122
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.0123rù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.01244
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0124
Đ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[] ¶ rùa. lên[] ¶Kéo bút lên – không vẽ khi di chuyển
rùa. kích thước[chiều rộng=Không có . ]¶turtle.chiều rộng[chiều rộng=Không có]¶Parameterschiều rộng – một số dương
Đặ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ẽ. Nếu không có đối số nào được đưa ra, thì pensize hiện tại được trả về
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0125rùa. bút[bút=Không có, **pendict]¶Parameters
bút – một từ điển với một số hoặc tất cả các phím được liệt kê bên dưới
pendict – một hoặc nhiều đối số từ khóa với các khóa được liệt kê bên dưới làm từ khóa
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
"cho xem". Đúng sai
"đặt bút xuống". Đúng sai
“màu bút”. chuỗi màu hoặc bộ màu
"tô màu". chuỗi màu hoặc bộ màu
“bù”. số dương
"tốc độ, vận tốc". số trong phạm vi 0. 10
"chế độ thay đổi kích thước". “tự động” hoặc “người dùng” hoặc “noresize”
“stretchfactor”. [số dương, số dương]
“outline”. số dương
“nghiêng”. con số
Từ điển này có thể được sử dụng làm đối số cho lệnh gọi tiếp theo tới
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0451 để khôi phục trạng thái bút cũ. Ngoài ra, một hoặc nhiều thuộc tính này có thể được cung cấp dưới dạng đối số từ khóa. Điều này có thể được sử dụng để đặt một số thuộc tính bút trong một câu lệnh
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0126rùa. ngừng hoạt động[] ¶
Trả lại
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01246 nếu bút xuống,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01247 nếu bút lên
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0127
Kiểm soát màu sắc¶
rùa. bút màu[*args]¶Trả lại hoặc đặt màu bút
Bốn định dạng đầu vào được cho phép
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0454
Trả về pencolor hiện tại dưới dạng chuỗi đặc tả màu hoặc dưới dạng bộ [xem ví dụ]. 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.01249
Đặ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.01250,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01251 hoặc
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01252
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01253
Đặ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, trong đó colormode là 1. 0 hoặc 255 [xem
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01208]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01255
Đặt pencolor thành màu RGB được biểu thị bằng r, g và 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.0128rùa. màu tô[*args]¶
Trả lại hoặc đặt màu tô
Bốn định dạng đầu vào được cho phép
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0455
Trả về màu tô hiện tại dưới dạng chuỗi đặc tả màu, có thể ở định dạng tuple [xem ví dụ]. 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.01257
Đặ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.01250,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01251 hoặc
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01252
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01261
Đặt màu tô thành màu RGB được biểu thị bằng bộ của r, g và b. Each of r, g, and b must be in the range 0. colormode, trong đó colormode là 1. 0 hoặc 255 [xem
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01208]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01263
Đặt màu tô thành màu RGB được biểu thị bằng r, g và 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, phần bên trong của đa giác đó được vẽ bằng màu tô 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.0129rùa. màu[*args]¶
Trả lại hoặc đặt pencolor và 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.0453
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.0454 và
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0455
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01267,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01268,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01269
Đầ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.0454, đặ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.01271,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01272
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.01273 và
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01274 và tương tự nếu định dạng đầu vào khác được sử dụng
Nếu hình con rùa là một đa giác, đường viền và phần bên trong của đa giác đó được vẽ bằng các 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.0400
Xem thêm. Phương pháp 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.01208
Đổ đầy¶
rùa. điền[] ¶Return fillstate [
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01246 if filling,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01247 else]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0401rùa. begin_fill[] ¶
To be called just before drawing a shape to be filled
rùa. 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.0457
Việc các vùng chồng lấp cho đa giác tự giao nhau hoặc nhiều hình có được lấp đầy hay không tùy thuộc vào đồ họa của hệ điều hành, loại chồng lấp và số lượng chồng lấp. For example, the Turtle star above may be either all yellow or have some white regions
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0402
Kiểm soát bản vẽ nhiều hơn¶
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.0403turtle. clear[] ¶
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']] ¶Parametersarg – 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]
Write text - the string representation of arg - at the current turtle position according to align [“left”, “center” or “right”] and with the given font. 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.01247
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0404
Turtle state¶
Visibility¶
turtle. hideturtle[] ¶ turtle. ht[] ¶Make the turtle invisible. It’s a good idea to do this while you’re in the middle of doing some complex drawing, because hiding the turtle speeds up the drawing observably
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0405turtle. 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.0406rùa. hiển thị[] ¶
Trả lại
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01246 nếu Rùa được hiển thị,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01247 nếu nó bị ẩn
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0407
Vẻ bề ngoài¶
rùa. hình dạng[tên=Không có]¶Parameterstên - một chuỗi là một shapename hợp lệ
Đặt hình dạng con rùa thành hình dạng với tên đã cho hoặc, nếu tên không được đặt, hãy trả về tên của hình dạng hiện tại. Hình dạng có tên phải tồn tại trong từ điển hình dạng của TurtleScreen. Ban đầu có các hình đa giác sau. “mũi tên”, “con rùa”, “hình tròn”, “hình vuông”, “hình tam giác”, “cổ điển”. Để tìm hiểu về cách xử lý các hình, hãy xem Phương pháp 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.01211
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0408rùa. resizemode[rmode=Không có]¶Parameters
rmode – một trong các chuỗi “auto”, “user”, “noresize”
Đặt resizemode thành một trong các giá trị. “tự động”, “người dùng”, “noresize”. Nếu rmode không được cung cấp, hãy trả về resizemode hiện tại. Các chế độ thay đổi kích thước khác nhau có các hiệu ứng sau
"Tự động". điều chỉnh sự xuất hiện của con rùa tương ứng với giá trị của pensize
"người sử dụng". điều chỉnh sự xuất hiện của con rùa theo các giá trị của hệ số kéo dài và chiều rộng đường viền [đường viền], được đặt bởi
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
469“noresize”. không có sự thích nghi nào về ngoại hình của con rùa diễn ra
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01284 được gọi bởi
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0469 khi được sử dụng với các đối số
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0409rùa. kích thước hình dạng[stretch_wid=Không có . , stretch_len=None, outline=None]¶turtle.kích thước rùa[stretch_wid=Không có, stretch_len=None, outline=None]¶Parameters
stretch_wid – số dương
stretch_len – số dương
đại cương – số dương
Trả lại hoặc đặt các thuộc tính x/y-stretchfactors và/hoặc phác thảo của bút. Đặt resizemode thành “người dùng”. Khi và chỉ khi chế độ thay đổi kích thước được đặt thành "người dùng", con rùa sẽ được hiển thị kéo dài theo các yếu tố kéo dài của nó. stretch_wid là hệ số kéo dài vuông góc với hướng của nó, stretch_len là hệ số kéo dài theo hướng của hướng của nó, đường viền xác định chiều rộng của đường viền của hình dạng
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0440rùa. máy cắt[máy cắt=Không có]¶Parameters
cắt - số [tùy chọn]
Đặt hoặc trả lại shearfactor hiện tại. Cắt hình rùa theo lực cắt shearfactor đã cho, là tiếp tuyến của góc cắt. Không thay đổi tiêu đề của rùa [hướng di chuyển]. Nếu cắt không được đưa ra. trả lại shearfactor hiện tại, tôi. e. tiếp tuyến của góc cắt, theo đó các đường song song với tiêu đề của con rùa bị cắt
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0441rùa. độ nghiêng[góc] ¶
góc – một số
Xoay hình con rùa theo góc so với góc nghiêng hiện tại của nó, nhưng không thay đổi hướng của con rùa [hướng di chuyển]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0442rùa. góc nghiêng[góc] ¶
góc – một số
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ì. Không thay đổi tiêu đề của rùa [hướng di chuyển]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0443
Không dùng nữa kể từ phiên bản 3. 1
rùa. nghiêng[góc=Không có]¶Parametersgóc – một số [tùy chọn]
Đặt hoặc trả về góc nghiêng hiện tại. 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ì. Không thay đổi tiêu đề của rùa [hướng di chuyển]. If angle is not given. trả lại góc nghiêng hiện tại, tôi. e. góc giữa hướng của hình con rùa và hướng của con rùa [hướng di chuyển của nó]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0444rùa. shapetransform[t11=None , t12=None , t21=None , t22=None] ¶Parameters
t11 – một số [tùy chọn]
t12 – a number [optional]
t21 – một số [tùy chọn]
t12 – a number [optional]
Đặ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. The determinant t11 * t22 - t12 * t21 must not be zero, otherwise an error is raised. 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.0445turtle. get_shapepoly[] ¶
Return the current shape polygon as tuple of coordinate pairs. This can be used to define a new shape or components of a compound shape
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0446
Using events¶
turtle. title[fun , btn=1 , add=None] Parametersfun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 [left mouse button]
add –
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246 or>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1247 – if>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246, a new binding will be added, otherwise it will replace a former binding
Bind fun to mouse-click events on this turtle. If fun is
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01229, existing bindings are removed. Example for the anonymous turtle, i. e. the procedural way
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0447turtle. onrelease[fun , btn=1 , add=None] ¶Parameters
fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 [left mouse button]
add –
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246 or>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1247 – if>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246, a new binding will be added, otherwise it will replace a former binding
Bind fun to mouse-button-release events on this turtle. If fun is
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01229, existing bindings are removed
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0448turtle. ondrag[fun , btn=1 , add=None] ¶Parameters
fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 [left mouse button]
add –
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246 or>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1247 – if>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246, a new binding will be added, otherwise it will replace a former binding
Bind fun to mouse-move events on this turtle. If fun is
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01229, existing bindings are removed
Remark. Every sequence of mouse-move-events on a turtle is preceded by a mouse-click event on that turtle
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0449
Subsequently, clicking and dragging the Turtle will move it across the screen thereby producing handdrawings [if pen is down]
Special Turtle methods¶
turtle. begin_poly[] ¶Start recording the vertices of a polygon. Current turtle position is first vertex of polygon
turtle. end_poly[] ¶Stop recording the vertices of a polygon. Current turtle position is last vertex of polygon. This will be connected with the first vertex
turtle. get_poly[] ¶Return the last recorded polygon
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0490turtle. clone[] ¶
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.0491turtle. getturtle[] ¶ turtle. getpen[] ¶
Return the Turtle object itself. Only reasonable use. as a function to return the “anonymous turtle”
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0492turtle. getscreen[] ¶
Return the
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.05 object the turtle is drawing on. TurtleScreen methods can then be called for that object
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0493turtle. setundobuffer[size] ¶Parameters
size – an integer or
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01229
Set or disable undobuffer. If size is an integer, an empty undobuffer of given size is installed. size gives the maximum number of turtle actions that can be undone by the
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0432 method/function. If size is
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01229, the undobuffer is disabled
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0494turtle. undobufferentries[] ¶
Return number of entries in the undobuffer
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0495
Compound shapes¶
To use compound turtle shapes, which consist of several polygons of different color, you must use the helper class
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04002 explicitly as described below
Create an empty Shape object of type “compound”
Add as many components to this object as desired, 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 methodFor example
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
496Now add the Shape to the Screen’s shapelist and use it
>>> 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ú
The
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04002 class is used internally by the
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01211 method in different ways. The application programmer has to deal with the Shape class only when using compound shapes like shown above
Methods of TurtleScreen/Screen and corresponding functions¶
Most of the examples in this section refer to a TurtleScreen instance called
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04006
Window control¶
turtle. bgcolor[*args] ¶Parametersargs – a color string or three numbers in the range 0. colormode or a 3-tuple of such numbers
Set or return background color of the TurtleScreen
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0498turtle. bgpic[picname=None] ¶Parameters
picname – a string, name of a gif-file or
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04007, or
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01229
Set background image or return name of current backgroundimage. If picname is a filename, set the corresponding image as background. If picname is
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04007, 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.01229, 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.0499turtle. clear[]
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.04011. 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.04012 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.04012turtle. 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.04014. The global function
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04015 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.04015turtle. resetscreen[] ¶
Reset all Turtles on the Screen to their initial state
turtle. screensize[canvwidth=None , canvheight=None , bg=None] ¶Parameterscanvwidth – positive integer, new width of canvas in pixels
canvheight – positive integer, new height of canvas in pixels
bg – colorstring or color-tuple, new background color
If no arguments are given, return current [canvaswidth, canvasheight]. Else resize the canvas the turtles are drawing on. Do not alter the drawing window. To observe hidden parts of the canvas, use the scrollbars. With this method, one can make visible those parts of a drawing which were outside the canvas before
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0500
e. g. to search for an erroneously escaped turtle ;-]
turtle. setworldcoordinates[llx , lly , urx , ury] ¶Parametersllx – a number, x-coordinate of lower left corner of canvas
lly – a number, y-coordinate of lower left corner of canvas
urx – a number, x-coordinate of upper right corner of canvas
ury – a number, y-coordinate of upper right corner of canvas
Set up user-defined coordinate system and switch to mode “world” if necessary. This performs a
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04017. If mode “world” is already active, all drawings are redrawn according to the new coordinates
ATTENTION. in user-defined coordinate systems angles may appear distorted
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0501
Animation control¶
turtle. delay[delay=None] ¶Parametersdelay – 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.0502turtle. 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.0495]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0503turtle. cập nhật[] ¶
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.0433
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.0498 to the title methodturtle. 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
1229key – 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.01229, 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.0498. ]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0504turtle. 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
1229key – 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.0498. ]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0505turtle. title[fun , btn=1 , add=None] ¶ turtle. onscreenclick[fun , btn=1 , add=None] ¶Parameters
fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas
btn – number of the mouse-button, defaults to 1 [left mouse button]
add –
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246 or>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1247 – if>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1246, a new binding will be added, otherwise it will replace a former binding
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.01229, 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.04006 and a Turtle instance named
>>> turtle.setheading[90] >>> turtle.heading[] 90.08
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0506
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.04032. The global function
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04033 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.04033turtle. 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.0507turtle. mainloop[] ¶ turtle. 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.0508
Input methods¶
rùa. textinput[title , prompt] ¶Parameterstitle – string
prompt – string
Pop up a dialog window for input of a string. Tiêu đề tham số là tiêu đề của cửa sổ hộp thoại, dấu nhắc là văn bản chủ yếu mô tả thông tin cần nhập. 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.01229
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0509rùa. số[tiêu đề , nhắc, default=None, minval=None, maxval=None]¶Parameters
title – string
prompt – string
mặc định – số [tùy chọn]
minval – số [tùy chọn]
maxval – số [tùy chọn]
Bật lên một cửa sổ hộp thoại để nhập số. tiêu đề là tiêu đề của cửa sổ hộp thoại, dấu nhắc là văn bản chủ yếu mô tả thông tin số cần nhập. mặc định. giá trị mặc định, minval. giá trị tối thiểu cho đầu vào, maxval. giá trị tối đa cho đầu vào. Đầu vào số phải nằm trong phạm vi minval. maxval if these are given. Nếu không, một gợi ý sẽ được đưa ra và hộp thoại vẫn mở để chỉnh sửa. Return the number input. Nếu hộp thoại bị hủy, hãy trả lại
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.01229
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0510
Cài đặt và phương pháp đặc biệt¶
rùa. chế độ[chế độ=Không có]¶Parameterschế độ – một trong các chuỗi “tiêu chuẩn”, “logo” hoặc “thế giới”
Đặt chế độ rùa [“tiêu chuẩn”, “logo” hoặc “thế giới”] và thực hiện đặt lại. Nếu chế độ không được cung cấp, chế độ hiện tại được trả về
Chế độ “tiêu chuẩn” tương thích với
>>> turtle.setheading[90] >>> turtle.heading[] 90.08 cũ. Chế độ “logo” tương thích với hầu hết đồ họa Logo rùa. Mode “world” uses user-defined “world coordinates”. Chú ý. 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.04038 unit-ratio doesn’t equal 1
Cách thức
tiêu đề rùa ban đầu
góc dương
"Tiêu chuẩn"
bên phải [phía đông]
ngược chiều kim đồng hồ
"Logo"
upward [north]
theo chiều kim đồng hồ
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0511turtle. chế độ màu[cmode=Không có]¶Parameters
cmode – một trong các giá trị 1. 0 hoặc 255
Trả về colormode hoặc đặt thành 1. 0 hoặc 255. Sau đó, các giá trị r, g, b của bộ ba màu phải nằm trong khoảng 0. *chế độ*
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0512turtle. getcanvas[] ¶
Trả lại Canvas của TurtleScreen này. Hữu ích cho những người trong cuộc biết phải làm gì với Tkinter Canvas
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0513rùa. hình dạng[] ¶
Trả về danh sách tên của tất cả các hình con rùa hiện có
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0514
Có ba cách khác nhau để gọi chức năng này
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
515Ghi 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
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
516tê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. Cài đặt hình ghép tương ứng
Add a turtle shape to TurtleScreen’s shapelist. Chỉ có thể sử dụng các hình dạng đã đăng ký như vậy bằng cách ban hành lệnh
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04041rùa. rùa[] ¶
Trả về danh sách rùa trê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.0517rùa. window_height[] ¶
Trả về chiều cao của cửa sổ con rùa
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0518turtle. 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.0519
Methods specific to Screen, not inherited from TurtleScreen¶
turtle. bye[] ¶Shut the turtlegraphics window
turtle. exit title[] ¶Ràng buộ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.01218 để nhấp chuột trên Màn hình
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.01247 [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.03 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.01246 in
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04046. In this case IDLE’s own mainloop is active also for the client scriptturtle. 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.04046 fileParameters
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 – nếu dương, vị trí bắt đầu tính bằng pixel từ cạnh trái của màn hình, nếu âm từ cạnh phải, nếu
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
1229, cửa sổ ở giữa theo chiều ngangbắt đầu – nếu dương, vị trí bắt đầu tính bằng pixel từ cạnh trên của màn hình, nếu âm từ cạnh dưới, của ________ 11229, cửa sổ ở giữa theo chiều dọc
>>> turtle.setheading[90] >>> turtle.heading[] 90.00rùa. tiêu đề[chuỗi tiêu đề] ¶
titlestring – một chuỗi được hiển thị trên thanh tiêu đề của cửa sổ đồ họa con rùa
Đặt tiêu đề của cửa sổ rùa thành chuỗi tiêu đề
>>> turtle.setheading[90] >>> turtle.heading[] 90.01
Lớp công lập¶
lớp rùa. RawTurtle[canvas] ¶ . class turtle.RawPen[canvas] ¶canvas – một
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.06, một
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.07 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.05
Tạo một con rùa. Rùa có tất cả các phương pháp được mô tả ở trên là “phương pháp của Rùa/RawTurtle”
lớp rùa. Con rùa ¶Lớp con của RawTurtle, có cùng giao diện nhưng dựa trên đối tượng mặc định là
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0407 được tạo tự động khi cần lần đầu tiênlớp rùa. TurtleScreen[cv] ¶
cv – một
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.06
Cung cấp các phương thức định hướng màn hình như
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04055, v.v. that are described abovelớp rùa. Màn hình ¶
Lớp con của TurtleScreen, với bốn phương thức được thêm vào .
lớp rùa. ScrolledCanvas[chính] ¶master – một số tiện ích Tkinter để chứa ScrolledCanvas, tôi. e. một Tkinter-canvas có thanh cuộn được thêm vào
Được sử dụng bởi lớp Screen, do đó tự động cung cấp ScrolledCanvas làm sân chơi cho rùa
lớp rùa. Hình dạng[loại_ , dữ liệu]¶Parameterstype_ – một trong các chuỗi “polygon”, “image”, “compound”
Hình dạng mô hình cấu trúc dữ liệu. Cặp
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.04056 phải tuân theo thông số kỹ thuật này
loại hình_
dữ liệu
“đa giác”
một đa giác-tuple, tôi. e. một bộ các cặp tọa độ
“image”
một hình ảnh [ở dạng này chỉ được sử dụng trong nội bộ. ]
"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.01229 [một hình ghép phải được dựng bằ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.04003]thêm thành phần[nhiều , điền, outline=None]¶Parameters
poly – một đa giác, i. e. một bộ các cặp số
tô màu – một màu poly sẽ được lấp đầy
phác thảo - một màu cho đường viền của poly [nếu có]
Thí dụ
>>> turtle.setheading[90] >>> turtle.heading[] 90.02
Xem Các hình ghép .
lớp rùa. Vec2D[x , y]¶A two-dimensional vector class, used as a helper class for implementing turtle graphics. Cũng có thể hữu ích cho các chương trình đồ họa rùa. Xuất phát từ bộ, vì vậy một vectơ là một bộ
Cung cấp [cho vectơ a, b, số k]
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
4059 cộng véc tơPhép trừ véc tơ
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
4060>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
4061 sản phẩm bên trongPhép nhân
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
4062 và>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
4063 với vô hướng>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
4064 giá trị tuyệt đối của aVòng quay
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0
4065
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
3Cá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=']¶Parameterstên tệp - một chuỗi, được sử dụng làm tên tệp
Create and write docstring-dictionary to a Python script with the given filename. 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.04067. It is intended to serve as a template for translation of the docstrings into different languages
Nếu bạn [hoặc học sinh của bạn] muốn sử dụng
>>> turtle.setheading[90] >>> turtle.heading[] 90.08 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.04069
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.04046 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.04046 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.05
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
4072Dò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
4073hì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
4074Nế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
4076Nế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 phụ”]. Đ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.04046 trong thư mục lưu trữ
>>> turtle.setheading[90] >>> turtle.heading[] 90.08 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.04085 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.04046. 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.04087 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.06
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.07
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.04087 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ậpTệ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ự mô 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.0496, trì hoãn,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0497
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.0479
rừng
3 cây theo chiều rộng
ngẫu nhiên hóa
đường cong fractal
Đường cong Hilbert & Koch
recursion
cây bồ đề
ethnomathematics [indian kolams]
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]
paint
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.0477
hòa bình
tiểu học
rùa. xuất hiện và hoạt hình
penrose
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.0429
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.01231
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.0483
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.0483,
>>> turtle.heading[] 90.0 >>> turtle.position[] [0.00,-10.00] >>> turtle.home[] >>> turtle.position[] [0.00,0.00] >>> turtle.heading[] 0.0432
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.0427
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. [In fact already in 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
458Mộ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ữaPhươ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
4424Phươ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ữaHai 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