Python Forum

Full Version: Hello, I am thinking if in python - is there a "check for color under you" command???
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Because I was tying to make a tron- like game... python
Attributes can always be checked.
Color is an attribute.
So the answer is yes.
So, can you please give me the command? Thanks. ;)
There is no one command.
It all depends on context.
please show some code, and specifically what 'under you' pertains to.
Like, if a turtle is touching a pecific color.

Code for the "tron" game(dosen't have the death function, please code it for me):
import turtle

troncycle = turtle.Turtle()
troncycle1 = turtle.Turtle()
screen = turtle.Screen()
troncycle.pensize(1)
troncycle.color("blue")
troncycle.pencolor("blue")
troncycle1.pensize(1)
troncycle1.color("orange")
troncycle1.pencolor("orange")


def moveforward():
    troncycle.forward(10)

def moveforward1():
    troncycle1.forward(10)

def moveright():
    troncycle.right(90)


def moveleft():
    troncycle.left(90)
    
    
def moveright1():
    troncycle1.right(90)


def moveleft1():
    troncycle1.left(90)


troncycle.forward(1)
troncycle1.forward(1)

screen.onkeypress(moveright, "Right")
screen.onkeypress(moveleft, "Left")
screen.onkeypress(moveright1, "d")
screen.onkeypress(moveleft1, "a")
screen.onkeypress(moveforward1, "w")
screen.onkeypress(moveforward, "Up")
    

screen.listen()
screen.mainloop()
sorry, but I just don't understand it...
Ok, I'm not a turtle guy, so you're going to have to play with this to get what you want, but
here's a routine to get the canvas attributes:
import turtle

troncycle = turtle.Turtle()
troncycle1 = turtle.Turtle()
screen = turtle.Screen()
troncycle.pensize(1)
troncycle.color("blue")
troncycle.pencolor("blue")
troncycle1.pensize(1)
troncycle1.color("orange")
troncycle1.pencolor("orange")


def moveforward():
    troncycle.forward(10)


def moveforward1():
    troncycle1.forward(10)


def moveright():
    troncycle.right(90)


def moveleft():
    troncycle.left(90)


def moveright1():
    troncycle1.right(90)


def get_color():
    cv = screen.getcanvas()
    cvitems = cv.__dict__
    for attribute in cvitems.items():
        print(attribute)

def moveleft1():
    troncycle1.left(90)


troncycle.forward(1)
troncycle1.forward(1)

screen.onkeypress(moveright, "Right")
screen.onkeypress(moveleft, "Left")
screen.onkeypress(moveright1, "d")
screen.onkeypress(moveleft1, "a")
screen.onkeypress(moveforward1, "w")
screen.onkeypress(moveforward, "Up")

get_color()

screen.listen()
screen.mainloop()
which will show:
Output:
('widgetName', 'frame') ('master', <turtle._Root object .>) ('tk', <_tkinter.tkapp object at 0x000000000298F430>) ('_name', '!scrolledcanvas') ('_w', '.!scrolledcanvas') ('children', {}) ('_tclCommands', []) ('_rootwindow', <turtle._Root object .>) ('width', 0.5) ('height', 0.75) ('canvwidth', 400) ('canvheight', 300) ('bg', 'white') ('_canvas', <tkinter.Canvas object .!canvas>) ('hscroll', <tkinter.Scrollbar object .!scrollbar>) ('vscroll', <tkinter.Scrollbar object .!scrollbar2>)
so to access just the color, (once cv has been defined) x = cv.bg
x = cv.bg
print('the color of x is: {}'.format(x))
Output:
the color of x is: white