from Tkinter import *
class Ball:
def __init__(self, canvas, x1, y1, x2, y2):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
self.canvas = canvas
self.ball = canvas.create_oval(self.x1, self.y1, self.x2, self.y2, fill="red")
# initialize root Window and canvas
root = Tk()
root.title("Balls")
root.resizable(False, False)
canvas = Canvas(root, width=300, height=300)
canvas.pack()
# create ball objects
ball = Ball(canvas, 0, 0, 300, 300)
root.mainloop()
As you see, I draw a 300*300 Oval in a 300*300 canvas, but the oval didn't fit the canvas perfectly. The result is(Mac OS):
So my question is:
EDIT:
ball = Ball(canvas, 1, 1, 299, 299)
doesn't work either, it gives:
The drawable area of the canvas is by default less than the total width and height of the canvas. The total size includes the widget border and the highlight ring. If you want the drawable area to be 100% of the width and height then you need to set both the borderwidth
and highlightthickness
attributes of the canvas to 0 (zero).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.