#1
  1. Caress me down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    Pennsylvania
    Posts
    289
    Rep Power
    511

    canvas in Tkinter


    i was woundering how you use canvas to place things in tkinter. can you mix canvas and grid? for example right now i have this program.

    Code:
    from Tkinter import *
    class App:
        def __init__(self, root):
            self.root = root
            Label(root, text='Hi').grid(row=0, column=0)
    root = Tk()
    app  = App(root)
    root.mainloop()
    i've tried to add this underneath Label but it doesn't work.
    Code:
    canvas = Canvas(root, width =400, height=400)
    canvas.create_rectangle(205,10,300,105, outline='white', fill='gray50')
    i don't get any errors but it doesn't draw the rectangle.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    You didn't pack the Canvas in your app. And what do you mean by "mix canvas and grid"? A canvas is a normal widget, as Labels and Buttons and ... so you have to pack it (using pack, grid or place) to see it.
    Code:
    canvas = Canvas(root, width =400, height=400)
    canvas.grid(row=1,column=0)
    canvas.create_rectangle(205,10,300,105, outline='white', fill='gray50')
    You should see the canvas now

    Regards, mawe
  4. #3
  5. Caress me down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    Pennsylvania
    Posts
    289
    Rep Power
    511
    ok i get it now. i thought canvas was just a different placing method like pack and grid. i thought it was like grid but it gave you more control over things and such. thanks for the help. i feel bad because you always have to answer my Tkinter questions.

IMN logo majestic logo threadwatch logo seochat tools logo