#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12

    Adding to Canvas (Ploting Point)


    Okay I have a program which makes a graph in a Canvas and everything works except the Ploting of points...

    Code:
    from Tkinter import *
    import math,Pmw
    
    class Grid:
        def __init__(self):
            self.root = Tk()
            self.Grid()
            self.root.mainloop()
    
        def Grid(self):
            self.Can = Canvas(self.root, width = 800, height = 700)
    
            self.Can.create_line(0,50,800,50)
            self.Can.create_line(0,100,800,100)
            self.Can.create_line(0,150,800,150)         # X cor ______________
            self.Can.create_line(0,200,800,200)
            self.Can.create_line(0,250,800,250)                
            self.Can.create_line(0,300,800,300)           # X middle
            self.Can.create_line(0,349,800,349,fill="blue")
            self.Can.create_line(0,350,800,350,fill="blue")
            self.Can.create_line(0,351,800,351,fill="blue")
            self.Can.create_line(0,400,800,400)
            self.Can.create_line(0,450,800,450)
            self.Can.create_line(0,500,800,500)
            self.Can.create_line(0,550,800,550)
            self.Can.create_line(0,600,800,600)
            self.Can.create_line(0,650,800,650)
            self.Can.create_line(0,700,800,700)
            self.Can.create_line(0,750,800,750)
    
            self.Can.create_line(50,0,50,700)
            self.Can.create_line(100,0,100,700)
            self.Can.create_line(150,0,150,700)
            self.Can.create_line(200,0,200,700)            # y cor |||||||||||||
            self.Can.create_line(250,0,250,700)
            self.Can.create_line(300,0,300,700)                 # Y middle
            self.Can.create_line(350,0,350,700)
            self.Can.create_line(399,0,399,700,fill="blue")
            self.Can.create_line(400,0,400,700,fill="blue")
            self.Can.create_line(401,0,401,700,fill="blue")
            self.Can.create_line(450,0,450,700)
            self.Can.create_line(500,0,500,700)
            self.Can.create_line(550,0,550,700)
            self.Can.create_line(600,0,600,700)
            self.Can.create_line(650,0,650,700)
            self.Can.create_line(700,0,700,700)
            self.Can.create_line(750,0,750,700)
    
            self.Can.create_rectangle(2,2,800,700)              # Box
    
            self.Can.create_text(405,357,text="0")              # xTexts +
            self.Can.create_text(455,357,text="1")
            self.Can.create_text(505,357,text="2")
            self.Can.create_text(555,357,text="3")
            self.Can.create_text(605,357,text="4")
            self.Can.create_text(655,357,text="5")
            self.Can.create_text(705,357,text="6")
            self.Can.create_text(755,357,text="7")
                                                             # xTexts -
            self.Can.create_text(355,357,text="-1")
            self.Can.create_text(305,357,text="-2")
            self.Can.create_text(255,357,text="-3")
            self.Can.create_text(205,357,text="-4")
            self.Can.create_text(155,357,text="-5")
            self.Can.create_text(105,357,text="-6")
            self.Can.create_text(55,357,text="-7")
            self.Can.create_text(5,357,text="-8")
                                                            # yTexts +
            self.Can.create_text(405,307,text="1")
            self.Can.create_text(405,257,text="2")
            self.Can.create_text(405,207,text="3")
            self.Can.create_text(405,157,text="4")
            self.Can.create_text(405,107,text="5")
            self.Can.create_text(405,57,text="6")
            self.Can.create_text(405,7,text="7")
                                                             # yTexts -
            self.Can.create_text(405,407,text="-1")
            self.Can.create_text(405,457,text="-2")
            self.Can.create_text(405,507,text="-3")
            self.Can.create_text(405,557,text="-4")
            self.Can.create_text(405,607,text="-5")
            self.Can.create_text(405,657,text="-6")
    
            self.Can.pack()
    
        def Plot(self,x,y):
            cx1 = x+5
            cy1 = y+5
            cx2 = x-5
            cy2 = y-5
    
            lx1 = x+2
            ly1 = y+2
            lx2 = x-2
            ly2 = y-2
    
            self.Can.create_line(lx1,ly1,lx2,ly2,fill="red")
            self.Can.create_oval(cx1,cy1,cx2,cy2,outline="red")
            
    if __name__ == "__main__":
        g = Grid()
        g.Plot(100,100)
    The Ploting does not work but I don't know why?
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    I've never used Tkinter in any of ym applications before. But I know that in wxPython when you are plotting the points for the place you want an object to appear, you use parentheses around each set of numbers. Where you have:
    Code:
    self.Can.create_line(0,50,800,50)
    Should it be:
    Code:
    self.Can.create_line((0,50), (800,50))
    ? I don't know Tkinter so I'm not sure what the true problem could be.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    Well I think I found the answer to the problem it has to be in the root and mianloop() between them not outside. which it is

    and the () is not true in tkinter aleast i dont think so since it is one object and two are needed they don't expect a tuple

IMN logo majestic logo threadwatch logo seochat tools logo