turtle-graphics

Find the cursor's current position in Python turtle

随声附和 提交于 2019-12-01 23:22:10
问题 How can I find the current mouse position in Python that can be integrated into turtle? I would prefer if you did not use any non-builtin modules (downloadable modules) Any answers would be appreciated 回答1: We can reach down into turtle's Tk underpinnings to enable the '<Motion>' event. I cast the function to set/unset the event to look like a method of the turtle screen but you can call it on the singular screen instance turtle.Screen() : import turtle def onmove(self, fun, add=None): """

PyCharm false syntax error using turtle

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 22:47:27
The code below works perfectly, however, PyCharm complains about syntax error in forward(100) #!/usr/bin/python from turtle import * forward(100) done() Since turtle is a stanrd library I don't think that I need to do additional configuration, am I right? alecxe The forward() function is made available for importing by specifying __all__ in the turtle module, relevant part from the source code : _tg_turtle_functions = [..., 'forward', ...] __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions + _tg_utilities + _math_functions) Currently, pycharm cannot see objects being listed

Find the cursor's current position in Python turtle

梦想与她 提交于 2019-12-01 21:34:30
How can I find the current mouse position in Python that can be integrated into turtle? I would prefer if you did not use any non-builtin modules (downloadable modules) Any answers would be appreciated We can reach down into turtle's Tk underpinnings to enable the '<Motion>' event. I cast the function to set/unset the event to look like a method of the turtle screen but you can call it on the singular screen instance turtle.Screen() : import turtle def onmove(self, fun, add=None): """ Bind fun to mouse-motion event on screen. Arguments: self -- the singular screen instance fun -- a function

Why is turtle lightening pixels?

不想你离开。 提交于 2019-12-01 16:28:54
My program for creating a Mandelbrot set has a bug: whenever the pen changes colors, and every 42nd pixel after that, is lighter. This is, rather coincidentally, a mandelbug (yes, I just learned that term), as it is inconsistent for many pixels near an "edge" (it might actually be blurred between the color it's supposed to be and the color the last, or next, pixel is supposed to be), but it's always the 42nd pixel after that one until the next color change. I am using OSX 10.6.8, PYTHON 2.7. When I wrote this program at school, it worked perfectly (Windows), and then I sent it to myself, and

Python turtle set start position

北慕城南 提交于 2019-12-01 12:30:40
How do I set the startpos (topleft of my turtle square) when starting my code? And I don't mean that it starts from the middle and then goes to that position. I want the turtle to start there. You can set the world coordinates to something else. For example, to start near the lower left corner, do: turtle.setworldcoordinates(-1, -1, 20, 20) This will make the entire window be 21x21 "units" and place the origin one unit from the bottom and left edges. Whatever position you command will also be in terms of these units (rather than pixels). Thomas Antony's setworldcoordinates() solution is viable

How do I make an object disappear after some time?

耗尽温柔 提交于 2019-12-01 11:43:23
I am trying to make a game where I can press space to shoot my bullet. There is a lot of lag. I am trying to figure out how to make the bullet disappear after it exits the screen. There is also a lot of lag. I am pretty sure the lag is from the bullet not resetting the screen after reaching the end. I imported time but I just can't seem to figure out how to use time. This is what I tried: # Importing GUI library import turtle import time bullets = [] bullets2 = [] # Set speed, GUI, creates new turtle t_speed = 5 bullet_speed = 50000 screen = turtle.Screen() t = turtle.Turtle() t2=turtle.Turtle

Python Turtle, draw text with on screen with larger font

戏子无情 提交于 2019-12-01 03:30:54
I'm using python turtle's write method to write text on the screen like this: turtle.write("messi fan") The size of the font is too small. How can I increase the size of font? Use the optional font argument to turtle.write() , from the docs: turtle.write( arg , move=False , align="left" , font=("Arial", 8, "normal") ) Parameters: arg – object to be written to the TurtleScreen move – True/False align – one of the strings “left”, “center” or right” font – a triple (fontname, fontsize, fonttype) So you could do something like turtle.write("messi fan", font=("Arial", 16, "normal")) to change the

Convert images drawn by turtle to PNG in Python

不羁的心 提交于 2019-12-01 02:18:15
问题 I'm making a abstract art template generator in Python that takes inputs of minimum radius, maximum radius, and number of circles. It draws random circles in random places, also meeting the user's specifications. I want to convert the Turtle graphics into a PNG so that the user can then edit the template however he/she wants to, but I don't know how to proceed. Here's my code: import random import time import turtle print("Abstract Art Template Generator") print() print("This program will

Save turtle output as jpeg

这一生的挚爱 提交于 2019-11-30 21:22:29
I have a fractal image creator. It creates a random fractal tree like thing. When done, it prompts the user to save the tree. I have it saving as a .svg right now and that works BUT I want it to save to a more convenient file type, like jpeg. Any ideas? Code: import turtle import random from sys import exit from time import clock import canvasvg turtle.colormode(255) red = 125 green = 70 blue = 38 pen = 10 def saveImg(): print("Done.") save = input("Would you like to save this tree? Y/N \n") if save.upper() == "Y": t.hideturtle() name = input("What would you like to name it? \n") nameSav =

How to Combine Tkinter windows?

ぐ巨炮叔叔 提交于 2019-11-30 18:10:57
问题 I have two groups of codes and the first part is a turtle graphics window and second part is a Tkinter window. How should I those two parts together to one window? My first part of the code from turtle import * def move(thing, distance): thing.circle(250, distance) def main(): rocket = Turtle() ISS = Turtle() bgpic('space.gif') register_shape("ISSicon.gif") ISS.shape("ISSicon.gif") rocket.speed(10) ISS.speed(10) counter = 1 title("ISS") screensize(750, 750) ISS.hideturtle() rocket.hideturtle(