I have create a frame but do not know how to draw the geometry on the sub-frame.
Here is the code of my current window:
class App:
def __init__(self, master):
frame = Frame(master)
frame.grid()
self.Quit = Button(frame, text = "QUIT", command = frame.quit)
self.Quit.grid(row = 0, column = 48, sticky = N)
self.adpt = Button(frame, text = "Add Point", command = self.adpt)
self.adpt.grid(row = 0, column = 49, sticky = N)
self.adln = Button(frame, text = "Add Line", command = self.adln)
self.adln.grid(row = 0, column = 50, sticky = N)
self.adpg = Button(frame, text = "Add Polygon", command = self.adpg)
self.adpg.grid(row = 0, column = 51, stick = N)
iframe = Frame(frame, bd = 2, relief = RAISED, width=1000, height=500)
iframe.grid(row = 1, columnspan = 100, sticky = N)
def adpt(self):
pass
def adln(self):
pass
def adpg(self):
pass
I need to create each kind of geometry by clicking the corresponding button, and then draw it on the sub-frame, but I do not know how to use event to draw geometry in the sub-frame (iframe). For example, to draw point, click the button "Add point". Then Click on the sub-frame to generate a point. Double click the sub-frame to save the points to a point list.
The first problem is how to draw the point on the sub-frame by click on it.
The second problem is how to make the sub-frame handle double click and click separately. When I double click a widget, it first go through the click event, and then the double click event.
I have create classes to draw geometry with canvas. The class of point, line, polygon can draw geometry with canvas.
Here is the example codes for point class:
class Point:
def __init__(self,x, y):
self.x = x
self.y = y
def __str__(self):
return " (" + str(self.x) + "," + str(self.y) + ")"
def draw(self,canvas):
canvas.create_line(self.x-10,self.y,self.x+10,self.y)
canvas.create_line(self.x,self.y-10,self.x,self.y+10)