Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 TKinter coordinate system (canvas)
I'm new to TKinter and I'm having trouble understanding the coordinate system being used. I can obviously use trial and error to draw whatever I want, but I prefer the system to make some sense to me so that I can make understandable code.

Anyway, for starters, I created a code snipet:
class Gui:
    def __init__(self, root):
        width, height = root.winfo_screenwidth(), root.winfo_screenheight()
        self.enter_fullscreen(root, width, height)

        self.canvas = Canvas(root)
        # self.canvas.config(highlightthickness=0)
        self.canvas.pack(fill=BOTH, expand=YES)

        self.screen = TurtleScreen(self.canvas)

        self.writer = RawTurtle(self.screen)

        self.draw_circle(180, "red", "blue")

    def enter_fullscreen(self, root, width, height):
        root.geometry('%dx%d+0+0' % (width, height))

    def draw_circle(self, radius, bg_color, border_color):
        circle_writer = RawTurtle(self.screen)
        self.canvas.create_oval(-radius/2, -radius/2, radius/2, radius/2, outline=border_color,
                           fill=bg_color, width=4)

def main():
    root = Tk()
    Gui(root = root)

if __name__ == '__main__':
The image was expected to be generated in the middle or be cropped bottom left. Instead, I got an image on the top right-ish (full image) (the image might be inverted (left to right)). May I please be adviced on how the cavas coordinates work? If I use ScrolledCanvas, the coordinates seem to work as expected, but I wish to use Canvas instead.

Never mind, I found the problem was due to self.canvas.pack(fill=BOTH, expand=YES). On removing this line and setting Canvas dimensions when setting the canvas (self.canvas = Canvas(root, width = width, height = height)), it works perfectly now.
you need a copy of shipman's tkinter reference manual
available here (and other locations):

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  tkinter canvas help pythonprogrammer 5 294 Dec-23-2019, 08:32 AM
Last Post: Malt
  [Tkinter] Scrollbar doesn't work on Canvas in Tkinter DeanAseraf1 3 2,643 Sep-19-2019, 03:26 PM
Last Post: joe_momma
  [Tkinter] Plotting Raster Data / TIFF files on tkinter canvas RRSCNGP 0 366 Aug-28-2019, 04:44 AM
Last Post: RRSCNGP
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 8,096 Jun-04-2019, 05:05 AM
Last Post: Gupi
  multiple coordinate systems, with real time plotting Wenzel3200 0 1,866 Jan-30-2018, 11:19 AM
Last Post: Wenzel3200

Forum Jump:

Users browsing this thread: 1 Guest(s)