turtle-graphics

How to stop the python turtle from drawing

纵饮孤独 提交于 2019-12-10 12:15:26
问题 Can anyone tell me why this code always has a line on the screen and also how to stop it? Slight problem with this is that every time this happens, I always get a line on my canvas no matter what I try to do. Any ideas on how to prevent this? Now this is probably too much code, but I have no idea how else to show the failing code. I have tried a variety of ways but none seem to work. def drawpixel(x, y, colour): turtle.goto(x, y) turtle.dot(1, colour) def main(): screen = turtle.Screen()

Python - Move Two Turtle Objects At Once

依然范特西╮ 提交于 2019-12-09 23:24:10
问题 I would like to create a program where one turtle object moves to where a user clicks their mouse, and a different turtle object moves at the same time. I have the first part, but I can't seem to get the rest to work. Any help would be appreciated. This is my code. (Credit for the first part of this goes to @Cygwinnian) from turtle import * turtle = Turtle() screen = Screen() screen.onscreenclick(turtle.goto) turtle.getscreen()._root.mainloop() turtle2 = Turtle() while True: turtle2.back(100)

Collisions aren't registering with Python Turtles

China☆狼群 提交于 2019-12-08 14:20:24
问题 I'm creating a simple 2D shooter following an online tutorial, and the enemy sprites (except 1, there are 5 total) are not abiding by my collision code. Everything works except the bullet object that the player controls simply passes right through the enemy sprites. Error messages I received: Traceback (most recent call last): File "C:\Python\Python36\pygame projects\space invaders.py", line 163, in <module> bullet.hideturtle() File "C:\Python\Python36\lib\turtle.py", line 2322, in hideturtle

Moving turtle in python

烈酒焚心 提交于 2019-12-08 11:58:38
问题 I need some help. I'm working on writing my initials with turtle in python, but for whatever reason I'm unable to make the turtle move. Even when the cursor moves, the turtle still starts in the middle of the screen. Even though I'm using penup() and pendown(). I've pared my code down to this: import turtle window = turtle.Screen() window.bgcolor("red") def draw_art(): charles = turtle.Turtle() charles.shape("turtle") charles.color("yellow") charles.speed(2) turtle.penup() turtle.goto(-100,50

How to make canvas bigger in turtles python

杀马特。学长 韩版系。学妹 提交于 2019-12-08 11:09:12
问题 I made a turtle drawing program in python, but my canvas in which the turtle draws is not big enough. I am trying to make this canvas bigger so that I can fit more on the page and make the stuff bigger. I am programming this in trinket.io. 回答1: I am programming this in trinket.io. That is your problem -- Unfortunately, this is not possible in trinket.io. Trinket.io does not support all the turtle methods. You can read which ones are supported here; I assume the rest are unsupported. This will

Multithreading With Python Turtle

ぐ巨炮叔叔 提交于 2019-12-08 07:34:27
Is there a way to use two turtles at the same time to draw two circles at the same time in one window? I tried this code but two turtles draw in separated windows from multiprocessing import Process import turtle t1=turtle.Turtle() t2=turtle.Turtle() def tes1(): t1.speed(0) i=0 while i < 360: t1.forward(1) t1.left(1) i+=1 def tes2(): t2.speed(0) i=0 while i < 360: t2.forward(1) t2.right(1) i+=1 if __name__ == '__main__': p1 = Process(target=tes1) p1.start() p2 = Process(target=tes2) p2.start() p1.join() p2.join() but somebody told me try multithreading but this code has a bad semantic error!!

How to detect X (close) button in python Turtle graphics?

故事扮演 提交于 2019-12-08 06:08:41
问题 When I click on the X (close) button while running a infinite loop of drawing in Turtle graphics, some error messages occurs. Here is an example: import turtle wn = turtle.Screen() tess = turtle.Turtle() while True: tess.forward(50) tess.left(120) tess.forward(50) wn.mainloop() When I close the window, then the following error message shows up. Traceback (most recent call last): File "/Users/user/Downloads/test.py", line 8, in <module> tess.forward(50) File "/Users/user/anaconda3/lib/python3

Turtle freehand drawing

匆匆过客 提交于 2019-12-08 05:25:05
问题 I'm working on a simple drawing program that combines Tkinter and Turtle modules. I would like to add an option that the user can draw anything by just using mouse similar to pen widget on Paint. I tried many things, I could not figure out how l can do it.How can l make the turtle draw anything (like pen widget on Paint ) on canvas by using mouse from tkinter import * import turtle sc=Tk() sc.geometry("1000x1000+100+100") fr4=Frame(sc,height=500,width=600,bd=4,bg="light green",takefocus=""

turtle delete writing on Screen and Rewrite

我与影子孤独终老i 提交于 2019-12-08 04:44:57
问题 In my code, under any function, I do: t = turtle.Turtle() t.write(name, font=("Arial", 11, "normal"), align="center") But when I change the screen, I want to delete this text, and rewrite it somewhere else. I know the "easy way out" of clearing the whole screen. But is there a way to delete just the writing? I have also tried drawing a white square over the text, but this did not work. Has anyone tried anything different? 回答1: At first, I thought this would be a simple matter of going back to

Function missing 2 required positional arguments: 'x' and 'y'

我的梦境 提交于 2019-12-07 17:10:08
问题 I am trying to write a Python turtle program that draws a Spirograph and I keep getting this error: Traceback (most recent call last): File "C:\Users\matt\Downloads\spirograph.py", line 36, in <module> main() File "C:\Users\matt\Downloads\spirograph.py", line 16, in main spirograph(R,r,p,x,y) File "C:\Users\matt\Downloads\spirograph.py", line 27, in spirograph spirograph(p-1, x,y) TypeError: spirograph() missing 2 required positional arguments: 'x' and 'y' >>> This is the code: from turtle