Đầu vào bàn phím rùa Python
Đồ họa con rùa là một cách phổ biến để giới thiệu lập trình cho trẻ em. Nó là một phần của ngôn ngữ lập trình Logo ban đầu được phát triển bởi Wally Feurzeig, Seymour Papert và Cynthia Solomon vào năm 1967 Show
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()) < 1: break end_fill() done() Bằng cách kết hợp các lệnh này với nhau và các lệnh tương tự, có thể dễ dàng vẽ các hình và ảnh phức tạp. Mô-đun >>> 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
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. Methods, of course, have the additional first argument self which is omitted here Overview of available Turtle and Screen methods¶Turtle methods¶Turtle motionMove and draw>>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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.0440Setting and measurement >>> 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.0466Xuất hiện >>> 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
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
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
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.043rùa. dấu xóa(n=Không)¶Parameters n – một số nguyên (hoặc >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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. Nếu không có đối số nào được đưa ra, hãy trả về tốc độ hiện tại Nếu đầu vào là một số lớn hơn 10 hoặc nhỏ hơn 0. 5, tốc độ được đặt thành 0. Dây tốc độ được ánh xạ tới các giá trị tốc độ như sau
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¶rùa. vị trí() ¶ rùa. tư thế() ¶Trả về vị trí hiện tại của con rùa (x,y) (dưới dạng vectơ >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01231) >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.047rùa. về phía(x , y=None)¶Parameters
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() ¶ Trả về tọa độ y của rùa >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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. khoảng cách(x , y=None)¶Parameters
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() ¶ turtle. up() ¶Pull the pen up – no drawing when moving turtle. kích thước(chiều rộng=Không có . )¶turtle.chiều rộng(chiều rộng=Không có)¶Parameterswidth – a positive number Đặt độ dày của đường thành chiều rộng hoặc trả lại. Nếu chế độ thay đổi kích thước được đặt thành “tự động” và hình con rùa là một đa giác, thì đa giác đó được vẽ với cùng độ dày nét vẽ. If no argument is given, the current pensize is returned >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0125turtle. bút(bút=Không có, **pendict)¶Parameters
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
This dictionary can be used as argument for a subsequent call to >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0451 to restore the former pen-state. Moreover one or more of these attributes can be provided as keyword-arguments. This can be used to set several pen attributes in one statement >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0126turtle. isdown() ¶ Return >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01246 if pen is down, >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01247 if it’s up >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0127 Color control¶rùa. pencolor(*args) ¶Return or set the pencolor Four input formats are allowed >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0454 Return the current pencolor as color specification string or as a tuple (see example). May be used as input to another color/pencolor/fillcolor call >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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, where colormode is either 1. 0 or 255 (see >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01208) >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01255 Set pencolor to the RGB color represented by r, g, and b. Mỗi r, g và b phải nằm trong phạm vi 0. chế độ màu Nếu hình con rùa là một đa giác, thì đường viền của đa giác đó được vẽ bằng bút màu mới được đặt >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0128rùa. màu tô(*args)¶ Trả lại hoặc đặt màu tô Four input formats are allowed >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0455 Return the current fillcolor as color specification string, possibly in tuple format (see example). Có thể được sử dụng làm đầu vào cho lệnh gọi color/pencolor/fillcolor khác >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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 Set fillcolor to the RGB color represented by the tuple of r, g, and b. Each of r, g, and b must be in the range 0. colormode, where colormode is either 1. 0 or 255 (see >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01208) >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01263 Set fillcolor to the RGB color represented by r, g, and b. Each of r, g, and b must be in the range 0. colormode If turtleshape is a polygon, the interior of that polygon is drawn with the newly set fillcolor >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0129rùa. color(*args) ¶ Return or set pencolor and fillcolor Một số định dạng đầu vào được cho phép. Họ sử dụng 0 đến 3 đối số như sau >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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 Equivalent to >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01273 and >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01274 and analogously if the other input format is used If turtleshape is a polygon, outline and interior of that polygon is drawn with the newly set colors >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0400 See also. Screen method >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01208 Filling¶turtle. filling() ¶Return fillstate ( >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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.0401turtle. begin_fill() ¶ To be called just before drawing a shape to be filled turtle. end_fill() ¶Fill the shape drawn after the last call to >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0457 Whether or not overlap regions for self-intersecting polygons or multiple shapes are filled depends on the operating system graphics, type of overlap, and number of overlaps. Ví dụ: ngôi sao Rùa ở trên có thể toàn màu vàng hoặc có một số vùng màu trắng >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0402 More drawing control¶turtle. reset() ¶Delete the turtle’s drawings from the screen, re-center the turtle and set variables to the default values >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0403turtle. xóa() ¶ Delete the turtle’s drawings from the screen. Do not move turtle. State and position of the turtle as well as drawings of other turtles are not affected turtle. write(arg , move=False , align='left' , font=('Arial', 8, 'normal')) ¶Parameters
Viết văn bản - biểu diễn chuỗi của arg - tại vị trí con rùa hiện tại theo căn chỉnh (“trái”, “giữa” hoặc “phải”) và với phông chữ đã cho. If move is true, the pen is moved to the bottom-right corner of the text. By default, move is >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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() ¶Làm cho con rùa vô hình. Bạn nên làm điều này khi đang thực hiện một số bản vẽ phức tạp, bởi vì việc ẩn con rùa sẽ tăng tốc độ vẽ một cách đáng kể >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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.0406turtle. isvisible() ¶ Return >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01246 if the Turtle is shown, >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01247 if it’s hidden >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0407 Appearance¶rùa. hình dạng(tên=Không có)¶Parametersname – a string which is a valid shapename Set turtle shape to shape with given name or, if name is not given, return name of current shape. Hình dạng có tên phải tồn tại trong từ điển hình dạng của TurtleScreen. Initially there are the following polygon shapes. “arrow”, “turtle”, “circle”, “square”, “triangle”, “classic”. To learn about how to deal with shapes see Screen method >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01211 >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0408turtle. resizemode(rmode=None) ¶Parameters rmode – one of the strings “auto”, “user”, “noresize” Set resizemode to one of the values. “auto”, “user”, “noresize”. Nếu rmode không được cung cấp, hãy trả về resizemode hiện tại. Different resizemodes have the following effects
>>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01284 is called by >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0469 when used with arguments >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0409turtle. shapesize(stretch_wid=None , stretch_len=None , outline=None) ¶ turtle. turtlesize(stretch_wid=None , stretch_len=None , outline=None) ¶Parameters
Return or set the pen’s attributes x/y-stretchfactors and/or outline. Set resizemode to “user”. If and only if resizemode is set to “user”, the turtle will be displayed stretched according to its stretchfactors. stretch_wid is stretchfactor perpendicular to its orientation, stretch_len is stretchfactor in direction of its orientation, outline determines the width of the shapes’s outline >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0440turtle. shearfactor(shear=None) ¶Parameters shear – number (optional) Set or return the current shearfactor. Shear the turtleshape according to the given shearfactor shear, which is the tangent of the shear angle. Do not change the turtle’s heading (direction of movement). Nếu cắt không được đưa ra. return the current shearfactor, i. e. the tangent of the shear angle, by which lines parallel to the heading of the turtle are sheared >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0441turtle. tilt(angle) ¶Parameters angle – a number Rotate the turtleshape by angle from its current tilt-angle, but do not change the turtle’s heading (direction of movement) >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0442turtle. settiltangle(angle) ¶Parameters angle – a number Xoay hình con rùa để chỉ theo hướng được chỉ định theo góc, bất kể góc nghiêng hiện tại của nó là gì. Do not change the turtle’s heading (direction of movement) >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0443 Deprecated since version 3. 1 angle – a number (optional) Set or return the current tilt-angle. Nếu góc được đưa ra, hãy xoay hình con rùa để chỉ theo hướng được chỉ định bởi góc, bất kể góc nghiêng hiện tại của nó là gì. Do not change the turtle’s heading (direction of movement). If angle is not given. return the current tilt-angle, i. e. the angle between the orientation of the turtleshape and the heading of the turtle (its direction of movement) >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0444rùa. shapetransform(t11=Không, t12=None, t21=None, t22=None)¶Parameters
Đặt hoặc trả về ma trận biến đổi hiện tại của hình con rùa Nếu không có phần tử nào của ma trận được đưa ra, hãy trả về ma trận biến đổi dưới dạng một bộ gồm 4 phần tử. Mặt khác, đặt các phần tử đã cho và biến đổi hình con rùa theo ma trận bao gồm hàng đầu tiên t11, t12 và hàng thứ hai t21, t22. Định thức t11 * t22 - t12 * t21 không được bằng 0, nếu không sẽ xảy ra lỗi. Modify stretchfactor, shearfactor and tiltangle according to the given matrix >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0445rùa. get_shapepoly() ¶ Return the current shape polygon as tuple of coordinate pairs. Điều này có thể được sử dụng để xác định một hình dạng mới hoặc các thành phần của một hình dạng ghép >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0446 Sử dụng sự kiện¶rùa. onclick(vui , btn=1, add=None)Parameters
Liên kết thú vị với các sự kiện nhấp chuột trên con rùa này. Nếu niềm vui là >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229, các ràng buộc hiện có sẽ bị xóa. Ví dụ cho con rùa vô danh, tôi. e. cách thủ tục >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0447rùa. ra mắt(vui , btn=1, add=None)¶Parameters
Liên kết thú vị với các sự kiện nhả nút chuột trên con rùa này. Nếu niềm vui là >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229, các ràng buộc hiện có sẽ bị xóa >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0448rùa. ondrag(vui , btn=1, add=None)¶Parameters
Liên kết các sự kiện di chuyển chuột thú vị trên con rùa này. Nếu niềm vui là >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229, các ràng buộc hiện có sẽ bị xóa Nhận xét. Mỗi chuỗi sự kiện di chuyển chuột trên một con rùa được bắt đầu bằng một sự kiện nhấp chuột trên con rùa đó >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0449 Sau đó, nhấp và kéo Rùa sẽ di chuyển nó trên màn hình do đó tạo ra các hình vẽ tay (nếu bút bị hỏng) Phương pháp rùa đặc biệt¶rùa. begin_poly() ¶Bắt đầu ghi các đỉnh của một đa giác. Vị trí con rùa hiện tại là đỉnh đầu tiên của đa giác rùa. end_poly() ¶Dừng ghi các đỉnh của một đa giác. Vị trí con rùa hiện tại là đỉnh cuối cùng của đa giác. Điều này sẽ được kết nối với đỉnh đầu tiên rùa. get_poly() ¶Trả lại đa giác được ghi cuối cùng >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0490rùa. nhân bản() ¶ Tạo và trả về một bản sao của con rùa với cùng vị trí, tiêu đề và thuộc tính của con rùa >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0491rùa. con rùa() ¶ con rùa. getpen() ¶ Trả lại chính đối tượng Rùa. Chỉ sử dụng hợp lý. như một chức năng để trả về "rùa ẩn danh" >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0492rùa. nhận màn hình() ¶ Trả lại đối tượng >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.05 mà con rùa đang vẽ. Các phương thức TurtleScreen sau đó có thể được gọi cho đối tượng đó >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0493rùa. setundobuffer(kích thước) ¶ size – một số nguyên hoặc >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229 Đặt hoặc vô hiệu hóa bộ đệm. Nếu kích thước là một số nguyên, một bộ hoàn tác trống có kích thước đã cho sẽ được cài đặt. size đưa ra số lượng hành động rùa tối đa có thể hoàn tác bằng phương thức/hàm >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0432. Nếu kích thước là >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229, bộ hoàn tác bị vô hiệu hóa >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0494rùa. các mục hoàn tác bộ đệm() ¶ Trả về số mục nhập trong bộ hoàn tác >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0495 Các hình ghép¶Để sử dụng các hình con rùa phức hợp, bao gồm một số đa giác có màu khác nhau, bạn phải sử dụng lớp trợ giúp >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04002 một cách rõ ràng như được mô tả bên dưới
Ghi chú Lớp >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04002 được sử dụng nội bộ bởi phương thức >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01211 theo nhiều cách khác nhau. Người lập trình ứng dụng chỉ phải xử lý lớp Hình dạng khi sử dụng các hình dạng phức hợp như được hiển thị ở trên Các phương thức của TurtleScreen/Screen và các chức năng tương ứng¶Hầu hết các ví dụ trong phần này đề cập đến một phiên bản TurtleScreen có tên là >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04006 Điều khiển cửa sổ¶rùa. bgcolor(*args)¶Parametersargs – một chuỗi màu hoặc ba số trong phạm vi 0. colormode hoặc một bộ 3 số như vậy Đặt hoặc trả về màu nền của TurtleScreen >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0498rùa. bgpic(picname=Không có)¶Parameters picname – một chuỗi, tên của tệp gif hoặc >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04007 hoặc >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229 Đặt hình nền hoặc trả về tên của hình nền hiện tại. Nếu picname là tên tệp, hãy đặt hình ảnh tương ứng làm nền. If picname is >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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. xóa() Ghi chú This TurtleScreen method is available as a global function only under the name >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04011. The global function >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04012 is a different one derived from the Turtle method >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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) ¶Parameters
Nếu không có đối số nào được đưa ra, hãy trả về giá trị hiện tại (canvaswidth, canvasheight). Khác thay đổi kích thước canvas mà rùa đang vẽ trên đó. Không thay đổi cửa sổ bản vẽ. Để quan sát các phần ẩn của canvas, hãy sử dụng thanh cuộn. Với phương pháp này, người ta có thể hiển thị các phần của bản vẽ nằm ngoài canvas trước đó. >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0500 e. g. để tìm kiếm một con rùa trốn thoát nhầm ;-) rùa. tọa độ setworld(llx , lly, urx, ury)¶Parameters
Thiết lập hệ tọa độ do người dùng định nghĩa và chuyển sang chế độ “thế giới” nếu cần. Điều này thực hiện một >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04017. Nếu chế độ “thế giới” đã hoạt động, tất cả các bản vẽ được vẽ lại theo tọa độ mới CHÚ Ý. trong các góc của hệ tọa độ do người dùng xác định có thể bị biến dạng >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0501 Điều khiển hoạt ảnh¶rùa. 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
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. update() ¶ Perform a TurtleScreen update. To be used when tracer is turned off See also the RawTurtle/Turtle method >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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 onclick methodturtle. onkey(fun , key) ¶ turtle. onkeyrelease(fun , key) ¶Parameters
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
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. onclick(fun , btn=1 , add=None) ¶ turtle. onscreenclick(fun , btn=1 , add=None) ¶Parameters
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. 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.04033 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.04033turtle. ontimer(fun , t=0) ¶Parameters
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.0507rùa. vòng lặp chính() ¶ rùa. done() ¶ Starts event loop - calling Tkinter’s mainloop function. Must be the last statement in a turtle graphics program. Must not be used if a script is run from within IDLE in -n mode (No subprocess) - for interactive use of turtle graphics >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0508 Input methods¶turtle. textinput(title , prompt) ¶Parameters
Pop up a dialog window for input of a string. Parameter title is the title of the dialog window, prompt is a text mostly describing what information to input. Return the string input. If the dialog is canceled, return >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229 >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0509turtle. numinput(title , prompt , default=None , minval=None , maxval=None) ¶Parameters
Pop up a dialog window for input of a number. title is the title of the dialog window, prompt is a text mostly describing what numerical information to input. default. default value, minval. minimum value for input, maxval. maximum value for input. The number input must be in the range minval . maxval if these are given. If not, a hint is issued and the dialog remains open for correction. Return the number input. If the dialog is canceled, return >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229 >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0510 Settings and special methods¶turtle. mode(mode=None) ¶Parametersmode – one of the strings “standard”, “logo” or “world” Set turtle mode (“standard”, “logo” or “world”) and perform reset. If mode is not given, current mode is returned Mode “standard” is compatible with old >>> turtle.setheading(90) >>> turtle.heading() 90.08. Mode “logo” is compatible with most Logo turtle graphics. Mode “world” uses user-defined “world coordinates”. Attention. in this mode angles appear distorted if >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04038 unit-ratio doesn’t equal 1 Mode Initial turtle heading positive angles “standard” to the right (east) counterclockwise “logo” upward (north) clockwise >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0511turtle. colormode(cmode=None) ¶Parameters cmode – one of the values 1. 0 or 255 Return the colormode or set it to 1. 0 or 255. Subsequently r, g, b values of color triples have to be in the range 0. *cmode* >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0512turtle. getcanvas() ¶ Trả lại Canvas của TurtleScreen này. Useful for insiders who know what to do with a Tkinter Canvas >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0513turtle. getshapes() ¶ Return a list of names of all currently available turtle shapes >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0514 Có ba cách khác nhau để gọi chức năng này
Add a turtle shape to TurtleScreen’s shapelist. Only thusly registered shapes can be used by issuing the command >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04041turtle. turtles() ¶ Return the list of turtles on the screen >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0517turtle. window_height() ¶ Return the height of the turtle window >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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. exitonclick() ¶Bind >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01218 method to mouse clicks on the Screen If the value “using_IDLE” in the configuration dictionary is >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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
>>> turtle.setheading(90) >>> turtle.heading() 90.00turtle. title(titlestring) ¶Parameters titlestring – a string that is shown in the titlebar of the turtle graphics window Set title of turtle window to titlestring >>> turtle.setheading(90) >>> turtle.heading() 90.01 Public classes¶class turtle. RawTurtle(canvas) ¶ class turtle. RawPen(canvas) ¶Parameterscanvas – a >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.06, a >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.07 or a >>> 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. The turtle has all methods described above as “methods of Turtle/RawTurtle” class turtle. Turtle ¶Subclass of RawTurtle, has the same interface but draws on a default >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0407 object created automatically when needed for the first timeclass turtle. TurtleScreen(cv) ¶Parameters cv – a >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.06 Provides screen oriented methods like >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04055 etc. that are described aboveclass turtle. Screen ¶ Subclass of TurtleScreen, with four methods added . class turtle. ScrolledCanvas(master) ¶Parametersmaster – some Tkinter widget to contain the ScrolledCanvas, i. e. a Tkinter-canvas with scrollbars added Used by class Screen, which thus automatically provides a ScrolledCanvas as playground for the turtles class turtle. Shape(type_ , data) ¶Parameterstype_ – one of the strings “polygon”, “image”, “compound” Data structure modeling shapes. The pair >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04056 must follow this specification type_ data “polygon” a polygon-tuple, i. e. a tuple of pairs of coordinates “image” an image (in this form only used internally. ) “compound” >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.01229 (a compound shape has to be constructed using the >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04003 method)addcomponent(poly , fill , outline=None) ¶Parameters
Example >>> turtle.setheading(90) >>> turtle.heading() 90.02 See Compound shapes . class turtle. Vec2D(x , y) ¶A two-dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs too. Derived from tuple, so a vector is a tuple Provides (for a, b vectors, k number)
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
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 Tạo và viết từ điển chuỗi tài liệu vào tập lệnh Python với tên tệp đã cho. Chức năng này phải được gọi rõ ràng (nó không được sử dụng bởi các lớp đồ họa con rùa). Từ điển chuỗi tài liệu sẽ được ghi vào tập lệnh Python >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.04067. Nó được dùng làm khuôn mẫu để dịch các chuỗi tài liệu sang các ngôn ngữ khác nhau Nếu bạn (hoặc học sinh của bạn) muốn sử dụng >>> turtle.setheading(90) >>> turtle.heading() 90.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
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
Các kịch bản demo là Tên Sự miêu tả Đặc trưng thiết kế phụ mô hình đồ họa rùa cổ điển phức tạp >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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 đệ quy cây bồ đề dân tộc học (kolams Ấn Độ) Hệ thống chữ L min_hanoi Tháp Hà Nội Rùa Chữ Nhật dạng đĩa Hà Nội (hình dáng, kích thước) nim chơi game nim cổ điển với ba đống gậy trên máy tính rùa như nimsticks, điều khiển sự kiện (chuột, bàn phím) Sơn chương trình vẽ siêu tối giản >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0477 hòa bình tiểu học rùa. xuất hiện và hoạt hình hoa hồng lát gạch định kỳ với diều và phi tiêu >>> turtle.heading() 90.0 >>> turtle.position() (0.00,-10.00) >>> turtle.home() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.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 thay đổi kể từ Python 3. 0¶
|