我已经创建了一个框架,但不知道如何在子框架上绘制几何图形。
这是我当前窗口的代码:
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
我需要通过点击相应的按钮来创建各种几何图形,然后在子框架上绘制它,但我不知道如何使用事件在子框架(iframe)中绘制几何图形。例如,要绘制点,请单击“添加点”按钮。然后点击子帧生成一个点。双击子帧将点保存到点列表中。
第一个问题是如何通过单击在子帧上绘制点。
第二个问题是如何使子框架手柄双击和单独单击。当我双击一个小部件时,它首先经过单击事件,然后是双击事件。
我创建了用画布绘制几何图形的类。点、线、多边形类可以用画布绘制几何图形。
以下是点类的示例代码:
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)