|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
做了一个用pyautocad画cad图的程序,然后想做图形界面化,正在测试基本功能,现在在做的事是 先设定中心点坐标,然后打开有让中心点上移和在中心点画图的两个按钮的界面。
但是现在运行程序,设定完中心点的xy坐标后,idle里一直在运行,界面不出来,就像是陷入死循环一样。是不是调图形界面就不能用input什么的?应该如何解决呢?
- import tkinter as tk
- import plant
- class APP:
- def __init__(self,master):
- frame = tk.Frame(master)
- frame.pack()
- self.changeUpCP = tk.Button(frame,text='向上移动位置',fg ='blue',command = plant.aa.changeUpCP())
- self.juxing = tk.Button(frame,text='画矩形',fg ='blue',command = plant.aa.juxing.plant())
- self.changeUpCP.pack()
-
- root =tk.Tk()
- root.title('画流程图')
- app = APP(root)
- root.mainloop()
复制代码
这里面导入的plant。py是这样的
- from pyautocad import Autocad, APoint,aDouble
- acad = Autocad(create_if_not_exists = True)
- import math
- import numpy as np
- pyacad = Autocad(create_if_not_exists=True)
- pyacad.prompt("Hello! AutoCAD from pyautocad.")
- print(pyacad.doc.Name)
- CPX = 500 #中心点 CenterPointX
- CPY = 500 # CenterPointY
- DeltaX = 50 #间距
- DeltaY = 30
- HW = 13 #HalfRWidth 矩形一半宽
- HH = 6.5 #HalfRHight 矩形一半高
- class SetPoint:
- CPX = 500 #中心点 CenterPointX
- CPY = 500 # CenterPointY
- def creat(self):
- self.juxing = Rectangle()
- self.lingxing = Choose()
- self.wenzi = InsertText()
- def set_CP(self):
- self.CPX = float(input('请输入x坐标:'))
- self.CPY = float(input('请输入y坐标:'))
- self.juxing.set_CP()
- self.lingxing.set_CP()
- self.wenzi.set_CP()
-
- def set_Delta(self):
- Delta = float(input('请设置间隔:'))
- DeltaX = Delta + 2*HW
- DeltaY = Delta + 2*HH
- def set_RWH(self):
- self.juxing.set_RWH()
- def set_RCH(self):
- self.lingxing.set_RWH()
- def changeUpCP(self):
- self.juxing.changeUpCP()
- self.lingxing.changeUpCP()
- self.wenzi.changeUpCP()
-
- def changeDownCP(self):
- self.juxing.changeDownCP()
- self.lingxing.changeDownCP()
- self.wenzi.changeDownCP()
- def changeLeftCP(self):
- self.juxing.changeLeftCP()
- self.lingxing.changeLeftCP()
- self.wenzi.changeLeftCP()
- def changeRightCP(self):
- self.juxing.changeRightCP()
- self.lingxing.changeRightCP()
- self.wenzi.changeRightCP()
- class Rectangle:
- HRW = 13 #HalfRWidth 矩形一半宽
- HRH = 6.5 #HalfRHight 矩形一半高
- DeltaX = 50 #间距
- DeltaY = 30
-
- def set_CP(self):
- self.CPX = aa.CPX
- self.CPY = aa.CPY
- def set_Delta(self):
- self.Delta = aa.Delta
- self.DeltaX = Delta + 2*HW
- self.DeltaY = Delta + 2*HH
- def set_RWH(self):
- self.HRW = float(input('请输入矩形的宽度:'))/2
- self.HRH = float(input('请输入矩形的高度:'))/2
- def changeUpCP(self):
- self.CPY = self.CPY + self.DeltaY
-
- def changeDownCP(self):
- self.CPY = self.CPY - self.DeltaY
- def changeLeftCP(self):
- self.CPX = self.CPX - self.DeltaX
- def changeRightCP(self):
- self.CPX = self.CPX + self.DeltaX
-
- def plant(self):
- x = [self.CPX-self.HRW,self.CPX+self.HRW,self.CPX+self.HRW,self.CPX-self.HRW]
- y = [self.CPY+self.HRH,self.CPY+self.HRH,self.CPY-self.HRH,self.CPY-self.HRH]
- pnts = [APoint(x[0], y[0]), APoint(x[1], y[1]), APoint(x[1], y[1]),
- APoint(x[2], y[2]), APoint(x[2], y[2]), APoint(x[3], y[3]),
- APoint(x[3], y[3]), APoint(x[0], y[0])]
- pnts = [j for i in pnts for j in i] # 将各点坐标顺序变换为行数据
- pnts = aDouble(pnts) # 转化为双精度浮点数
- plineObj = pyacad.model.AddPolyLine(pnts)
- plineObj.Closed = True # 闭合多段线
-
- class Choose:
- HCW = 13 #HalfRWidth 矩形一半宽
- HCH = 6.5 #HalfRHight 矩形一半高
- DeltaX = 50 #间距
- DeltaY = 30
-
- def set_CP(self):
- self.CPX = aa.CPX
- self.CPY = aa.CPY
- def set_Delta(self):
- self.Delta = aa.Delta
- self.DeltaX = Delta + 2*HW
- self.DeltaY = Delta + 2*HH
- def set_CWH(self):
- self.HCW = float(input('请输入菱形的宽度:'))/2
- self.HCH = float(input('请输入菱形的高度:'))/2
- def changeUpCP(self):
- self.CPY = self.CPY + self.DeltaY
-
- def changeDownCP(self):
- self.CPY = self.CPY - self.DeltaY
- def changeLeftCP(self):
- self.CPX = self.CPX - self.DeltaX
- def changeRightCP(self):
- self.CPX = self.CPX + self.DeltaX
- def plant(self):
- x = [self.CPX,self.CPX+self.HCW,self.CPX,self.CPX-self.HCW]
- y = [self.CPY+self.HCH,self.CPY,self.CPY-self.HCH,self.CPY]
- pnts = [APoint(x[0], y[0]), APoint(x[1], y[1]), APoint(x[1], y[1]),
- APoint(x[2], y[2]), APoint(x[2], y[2]), APoint(x[3], y[3]),
- APoint(x[3], y[3]), APoint(x[0], y[0])]
- pnts = [j for i in pnts for j in i] # 将各点坐标顺序变换为行数据
- pnts = aDouble(pnts) # 转化为双精度浮点数
- plineObj = pyacad.model.AddPolyLine(pnts)
- plineObj.Closed = True # 闭合多段线
- class InsertText:
- DeltaX = 50 #间距
- DeltaY = 30
-
- def set_CP(self):
- self.CPX = aa.CPX
- self.CPY = aa.CPY
- def set_Delta(self):
- self.Delta = aa.Delta
- self.DeltaX = Delta + 2*HCW
- self.DeltaY = Delta + 2*HCH
- def changeUpCP(self):
- self.CPY = self.CPY + self.DeltaY
-
- def changeDownCP(self):
- self.CPY = self.CPY - self.DeltaY
- def changeLeftCP(self):
- self.CPX = self.CPX - self.DeltaX
- def changeRightCP(self):
- self.CPX = self.CPX + self.DeltaX
-
- def in_text(self):
- p = APoint(self.CPX,self.CPY)
- text = input('请输入要插入的文字')
- #text = acad.model.AddText('Hi !' , p, 2.5)
- insert = acad.model.AddText("{0}".format(text), p, 3)
-
- aa=SetPoint()
- aa.creat()
- aa.set_CP()
-
-
复制代码
你要问我原理,讲不清楚,但就是这么用的
你要调用的是plant里类下面的某个方法,那就用
- command=plant.SetPoint().a
复制代码的形式,
不般不会去引用实例化后的对象,具体对不对,等其他大佬解释和指出错误
一般定义类,都是class SetPoint(),会带个括号
command等号后面跟着的是方法名,所以方法a会面没有括号
你的代码,我没有pyautocad 所以没法运行
但如果使用您说的command = plant.aa.juxing().plant,会报错啊?
我没有说用这样的形式,我说的是command=模块名.类名.方法名
|
|