Hi.
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:
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.
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.screen.clearscreen()
self.screen.bgcolor("black")
self.writer = RawTurtle(self.screen)
self.writer.reset()
self.writer.speed(0)
self.draw_circle(180, "red", "blue")
def enter_fullscreen(self, root, width, height):
root.overrideredirect(True)
root.geometry('%dx%d+0+0' % (width, height))
def draw_circle(self, radius, bg_color, border_color):
circle_writer = RawTurtle(self.screen)
circle_writer.ht()
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)
root.mainloop()
if __name__ == '__main__':
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.
