LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Draw a Pixel with Python (https://www.linuxquestions.org/questions/programming-9/draw-a-pixel-with-python-626513/)

geek_man 03-07-2008 08:14 PM

Draw a Pixel with Python
 
Hi!

I am trying to draw a pixel with python, but I can't. I am using this:

canvas = Canvas(width=500, height=500, bg='white')
canvas.pack(expand=YES, fill=BOTH)
canvas.SetPixel(x,y,color)

But I get the following error:

AttributeError: Canvas instance has no attribute 'SetPixel'

I have read in Internet that SetPixel really exists. Can someone help me?

Thanks.

pgpython 03-08-2008 02:19 AM

First of all you should say what GUI toolkit you are working with: Is it Tk, wxPython, PyQT, PyGTK or something else entirely. If your seriously stuck on what methods a module has dir() and help() are the way to go as every decent GUI has python doc strings in the package

just do something like this:

Code:

import module
dir(module)
help(module.method_name)


geek_man 03-08-2008 10:43 AM

Hi!

I am a beginner in Python, so I don't know so much. I am using Tkinter GUI Toolkit.
pgpython, do I have to do the following?:
Code:

from Tkinter import Canvas
dir(Canvas)
help(Canvas.SetPixel)

Thanks.

pgpython 03-08-2008 11:49 AM

yes dir returns a list of all the methods and attributes a object has, while help returns the doc string for a attribute. Hence their usefulness. Sorry i can't be of more but I haven't used tkinter for a long time


All times are GMT -5. The time now is 05:04 PM.