Python Forum
Hello, I am thinking if in python - is there a "check for color under you" command???
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hello, I am thinking if in python - is there a "check for color under you" command???
#1
Because I was tying to make a tron- like game... python
Reply
#2
Attributes can always be checked.
Color is an attribute.
So the answer is yes.
Reply
#3
So, can you please give me the command? Thanks. ;)
Reply
#4
There is no one command.
It all depends on context.
please show some code, and specifically what 'under you' pertains to.
Reply
#5
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()
Reply
#6
see: https://stackoverflow.com/questions/4162...ing-colour
Reply
#7
sorry, but I just don't understand it...
Reply
#8
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 903 Oct-25-2023, 09:09 AM
Last Post: codelab
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 6,689 Mar-02-2022, 01:23 AM
Last Post: tomtom
  Python "thinking" help DrManhattan71 0 1,255 Nov-29-2020, 01:50 PM
Last Post: DrManhattan71
  Python function call font color JeffR1992 1 3,372 Apr-17-2019, 06:38 AM
Last Post: perfringo
  Change Text Color Output in Python bluethundr 2 8,676 Mar-06-2019, 10:23 PM
Last Post: bluethundr
  modify the color a string of characters in python 3.6 atlass218 10 5,506 Feb-28-2019, 03:20 PM
Last Post: atlass218
  Is there a way to detect the text font, size and color from an image in python? Maia07 2 8,582 Aug-23-2018, 01:16 PM
Last Post: Maia07
  Sending different color codes in python at certain times Kimzer 4 3,378 Jun-18-2018, 06:56 PM
Last Post: gontajones
  Python/Tkinter button color changing Crawford3 7 46,268 Aug-10-2017, 02:07 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020