本文整理汇总了Python中Canvas类的典型用法代码示例。如果您正苦于以下问题:Python Canvas类的具体用法?Python Canvas怎么用?Python Canvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Canvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setGconmember
def setGconmember(self,member,value):
# If the VCS Canvas is displayed, then bring the canvas to the front before
# redisplaying the updated contents.
if (self.parent.mode == 1) and (self.parent.iscanvasdisplayed()):
Canvas.finish_queued_X_server_requests( self.parent )
self.parent.canvas.BLOCK_X_SERVER()
self.parent.canvasraised()
_vcs.setGconmember(self, member, value, self.parent.mode)
# If the VCS Canvas is displayed, then update the backing store
if (self.parent.mode == 1) and (self.parent.iscanvasdisplayed()):
self.parent.flush()
self.parent.backing_store()
self.parent.canvas.UNBLOCK_X_SERVER()
示例2: show
def show(self):
self.tk.wm_title(self.title)
self.board = Canvas(self.tk,relief=SUNKEN, bd=2, width=self.ww, height=self.wh)
self.board.pack(fill=BOTH)
Rectangle(self.board, (0,0), (self.ww,self.wh), fill="white", width=1)
b = Button(self.tk, text="Close", font=self.font, command = self.close )
b.pack()
示例3: __init__
def __init__(self, master, frame, sw, sh):
'''
Constructor for the plot area.
'''
# initialization of
self.sw = sw
self.sh = sh
self.frame = frame
# empty value list
self.value_list = []
# canvas area where the value lines and the coordinate system
self.canvas = Canvas(self.frame, bg = "white")
self.canvas.pack(expand = YES, fill = BOTH)
#if the used os is a windows or a mac, they need a factor 1.5 for the y-axis
if os.name == "nt":
self.win_osx_factor = 1.5
elif os.name == "mac":
self.win_osx_factor = 1.5
# if its a linux machine factor is 1
else:
self.win_osx_factor = 1
示例4: __init__
class SonarScanner:
def __init__(self, sonarPort, motorPort):
self.motor = MotorScanner(motorPort)
self.sonar = Sonar(sonarPort)
self.canvas = Canvas()
#
# Function to scan from 0 to 360. Each step takes SCAN_STEP Radian
def scan(self):
# initialize data
data = []
# Go to start angle
self.motor.gotoAngle(SCANNER_START_ANGLE, 'cw')
nStep = int((SCANNER_END_ANGLE - SCANNER_START_ANGLE)/SCANNER_SCAN_STEP)
for i in range(0, nStep):
# go to angle
angle = SCANNER_START_ANGLE + SCANNER_SCAN_STEP*i
self.motor.gotoAngle(angle, 'ccw')
# read sonar data
z = self.sonar.getSmoothSonarDistance(0.05)
data.append(z)
# Back to zero angle
self.motor.gotoAngle(0, 'cw')
return data
def drawScanData(self, data):
for i in range(0, len(data)):
r = data[i]*SCANNER_DRAW_SCALE
th = SCANNER_START_ANGLE + SCANNER_SCAN_STEP*i
if(r > 200):
continue
x0 = int(SCANNER_DRAW_X0)
y0 = int(SCANNER_DRAW_Y0)
x1 = int(x0 + r*cos(th))
y1 = int(y0 + r*sin(th))
print radToDeg(th), r
print (x0, y0, x1, y1)
self.canvas.drawLine((x0, y0, x1, y1))
示例5: __init__
def __init__(self, parent=None):
super(Mozayik, self).__init__(parent)
mainLayout = QHBoxLayout()
#setup button icons
assets = os.getcwd() + "/assets"
if os.path.exists(assets):
os.chdir(assets)
trash = assets + "/trash.png"
if os.path.isfile(trash):
trashIcon = QIcon(QPixmap(trash))
add = assets + "/plus.png"
if os.path.isfile(add):
addIcon = QIcon(QPixmap(add))
folder = assets + "/folder.png"
if os.path.isfile(folder):
folderIcon = QIcon(QPixmap(folder))
#setup buttons
self.enterFolderButton = QPushButton(folderIcon, "")
self.enterFolderButton.clicked.connect(self.enterFolderContact)
self.addTilesButton = QPushButton(addIcon, "")
self.addTilesButton.clicked.connect(self.addTilesContact)
self.deleteButton = QPushButton(trashIcon, "")
self.deleteButton.clicked.connect(self.deleteContact)
#layout buttons
buttonLayout1 = QHBoxLayout()
buttonLayout1.addWidget(self.enterFolderButton)
buttonLayout1.addWidget(self.addTilesButton)
buttonLayout1.addWidget(self.deleteButton)
#setup image viewer
scrollView = QScrollArea()
scrollView.setBackgroundRole(QPalette.Dark)
self.viewer = Viewer()
scrollView.setWidget(self.viewer)
size = QSize(350,600)
scrollView.setMaximumSize(size)
#scrollView.setMinimumSize(size)
#setup mozayik area
#self.mozayik = QLabel("Area reserved")
self.mozayik = Canvas()
#layout main view
viewLayout1 = QVBoxLayout()
viewLayout1.addLayout(buttonLayout1)
viewLayout1.setAlignment(buttonLayout1,Qt.AlignRight)
viewLayout1.addWidget(scrollView)
viewLayout1.setAlignment(scrollView,Qt.AlignLeft)
mainLayout.addLayout(viewLayout1)
mainLayout.addWidget(self.mozayik)
self.setLayout(mainLayout)
self.setWindowTitle("Mozayik")
示例6: __construct__
def __construct__(self):
#extract, contain, and properly indent python content
funcname = self.vbl_elem.getAttribute('name')
args = self.vbl_elem.getAttribute('args')
script = Canvas.normalize_python(node=self, definition="def %s(%s):"%(funcname, args))
#run the code (which will define a function where we need it)
try: exec script in self.parent.__dict__
except Exception, msg: Events.Error(self, msg, "bad syntax in python block")
示例7: __init__
class CanvasDemo:
colors = ["pink", "grey", "yellow", "green", "red", "purple", "cyan",
"pink", "grey", "yellow", "green", "red", "purple", "cyan",
"pink", "grey", "yellow", "green", "red", "purple", "cyan"]
layers = 5
root = canvas = groups = None
def __init__(self, root):
self.root = root
# make a frame and a canvas and some buttons
frame = Frame(self.root)
frame.pack(fill=X)
label = Label(frame, text="Canvas test")
label.pack()
self.canvas = Canvas(frame, bg="grey", width=600, height=600)
self.canvas.pack()
cmd = Button(frame, text="Scale", command=self.scale)
cmd.pack()
self.groups = []
for i in range(self.layers):
self.groups.append(Group(self.canvas))
# time the creation of the rectangles
start = time()
self.makeShapes()
print "Took ", time() - start, " seconds to make", self.layers,"layers"
def makeShapes(self):
# make 100 rectangles
for group in range(self.layers):
actual = self.groups[group]
MouseHandler(actual)
for i1 in range(10):
for i2 in range(10):
makeRectangle(self.canvas, actual, i1*40+10+group*20,
i2*40+10+group*5,
35, 35, self.colors[group], 2)
def scale(self):
for group in self.groups:
group.scale(0, 0, 1.1, 1.1)
示例8: __init__
def __init__(self, app):
"""
Create a main window for the given application.
"""
defaultOptions["palette"] = app.palette()
Systray.__init__(self)
self.expansions = 0
self.client = None
self.server = None
self.running = False
self.recovery = False
mainWidgets["main"] = self
mainWidgets["app"] = app
self.canvas = Canvas(self)
mainWidgets["canvas"] = self.canvas
self.tabWidget = TabWidget(self)
mainWidgets["tab"] = self.tabWidget
self.setCentralWidget(self.tabWidget)
# self.setCentralWidget(self.canvas)
self.createActions()
self.createMenus()
self.createToolBars()
self.createStatusBar()
self.createDockWindows()
self.createConfigWindows()
self.createPopupWindows()
self.createProgressBar()
self.newScene()
self.debugWindow.hide()
self.tm.hide()
self.routes.hide()
self.setVisible(True)
self.center()
self.saveLayout(environ["config"] + "defaultLayout")
self.defaultLayout = True
if options["restore"]:
self.loadLayout()
self.defaultLayout = False
self.loadProject()
atexit.register(self.cleanup)
示例9: closeTopology
def closeTopology(self):
"""
Close the current topology.
"""
if self.running:
self.log.append("You cannot close a topology when one is still running!")
return False
scene = self.canvas.scene()
if scene and scene.items():
reply = QtGui.QMessageBox.warning(
self,
self.tr(Core.globals.PROG_NAME),
self.tr("Save before closing?"),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel,
)
if reply == QtGui.QMessageBox.Yes:
if not self.saveTopology():
return False
elif reply == QtGui.QMessageBox.No:
pass
else:
return False
if isinstance(mainWidgets["canvas"], Tutorial):
self.canvas = Canvas(self)
mainWidgets["canvas"] = self.canvas
self.tabWidget.removeTab(0)
self.tabWidget.addTab(self.canvas, "Default Project")
self.project = ""
self.unlockDocks()
self.filename = ""
scene = Scene(self.canvas)
scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
self.canvas.setScene(scene)
self.expansions = 0
for nodeType in nodeTypes.keys():
itemTypes = nodeTypes[nodeType]
itemTypes[nodeType] = 0
self.properties.clear()
self.interfaces.clear()
self.routes.clear()
return True
示例10: __initUI
def __initUI(self):
self.parent.title("Sudoku")
self.pack(fill=BOTH)
self.canvas = Canvas(self,
width=WIDTH,
height=HEIGHT)
self.canvas.pack(fill=BOTH, side=TOP)
clear_button = Button(self,
text="Clear answers",
command=self.__clear_answers)
clear_button.pack(fill=BOTH, side=BOTTOM)
self.__draw_grid()
self.__draw_puzzle()
self.canvas.bind("<Button-1>", self.__cell_clicked)
self.canvas.bind("<Key>", self.__key_pressed)
示例11: SudokuUI
class SudokuUI(Frame):
"""
The Tkinter UI, responsible for drawing the board and accepting user input.
"""
def __init__(self, parent, game):
self.game = game
Frame.__init__(self, parent)
self.parent = parent
self.row, self.col = -1, -1
self.__initUI()
def __initUI(self):
self.parent.title("Sudoku")
self.pack(fill=BOTH)
self.canvas = Canvas(self,
width=WIDTH,
height=HEIGHT)
self.canvas.pack(fill=BOTH, side=TOP)
clear_button = Button(self,
text="Clear answers",
command=self.__clear_answers)
clear_button.pack(fill=BOTH, side=BOTTOM)
self.__draw_grid()
self.__draw_puzzle()
self.canvas.bind("<Button-1>", self.__cell_clicked)
self.canvas.bind("<Key>", self.__key_pressed)
def __draw_grid(self):
"""
Draws grid divided with blue lines into 3x3 squares
"""
for i in xrange(10):
color = "blue" if i % 3 == 0 else "gray"
x0 = MARGIN + i * SIDE
y0 = MARGIN
x1 = MARGIN + i * SIDE
y1 = HEIGHT - MARGIN
self.canvas.create_line(x0, y0, x1, y1, fill=color)
x0 = MARGIN
y0 = MARGIN + i * SIDE
x1 = WIDTH - MARGIN
y1 = MARGIN + i * SIDE
self.canvas.create_line(x0, y0, x1, y1, fill=color)
def __draw_puzzle(self):
self.canvas.delete("numbers")
for i in xrange(9):
for j in xrange(9):
answer = self.game.puzzle[i][j]
if answer != 0:
x = MARGIN + j * SIDE + SIDE / 2
y = MARGIN + i * SIDE + SIDE / 2
original = self.game.start_puzzle[i][j]
color = "black" if answer == original else "sea green"
self.canvas.create_text(
x, y, text=answer, tags="numbers", fill=color
)
def __draw_cursor(self):
self.canvas.delete("cursor")
if self.row >= 0 and self.col >= 0:
x0 = MARGIN + self.col * SIDE + 1
y0 = MARGIN + self.row * SIDE + 1
x1 = MARGIN + (self.col + 1) * SIDE - 1
y1 = MARGIN + (self.row + 1) * SIDE - 1
self.canvas.create_rectangle(
x0, y0, x1, y1,
outline="red", tags="cursor"
)
def __draw_victory(self):
# create a oval (which will be a circle)
x0 = y0 = MARGIN + SIDE * 2
x1 = y1 = MARGIN + SIDE * 7
self.canvas.create_oval(
x0, y0, x1, y1,
tags="victory", fill="dark orange", outline="orange"
)
# create text
x = y = MARGIN + 4 * SIDE + SIDE / 2
self.canvas.create_text(
x, y,
text="You win!", tags="victory",
fill="white", font=("Arial", 32)
)
def __cell_clicked(self, event):
if self.game.game_over:
return
x, y = event.x, event.y
if (MARGIN < x < WIDTH - MARGIN and MARGIN < y < HEIGHT - MARGIN):
self.canvas.focus_set()
# get row and col numbers from x,y coordinates
#.........这里部分代码省略.........
示例12: transformToWindowCoordinates
def transformToWindowCoordinates(points):
return [[(1 + t[0]) * WIDTH / 2 , (1 - t[1]) * HEIGHT / 2] for t in points]
if __name__ == "__main__":
#check parameters
if len(sys.argv) != 2:
print "pointViewerTemplate.py"
sys.exit(-1)
# create main window
mw = Tk()
# create and position canvas and buttons
cFr = Frame(mw, width=WIDTH, height=HEIGHT, relief="sunken", bd=1)
cFr.pack(side="top")
can = Canvas(cFr, width=WIDTH, height=HEIGHT)
can.pack()
bFr = Frame(mw)
bFr.pack(side="left")
bRotYn = Button(bFr, text="<-", command=rotYn)
bRotYn.pack(side="left")
bRotYp = Button(bFr, text="->", command=rotYp)
bRotYp.pack(side="left")
eFr = Frame(mw)
eFr.pack(side="right")
bExit = Button(eFr, text="Quit", command=(lambda root=mw: quit(root)))
bExit.pack()
modelObj = model.parse(sys.argv[1])
cam.setupCameraForModel(modelObj)
示例13: draw
draw()
if __name__ == "__main__":
#check parameters
if len(sys.argv) != 1:
print "LineClipping"
sys.exit(-1)
# create main window
mw = Tk()
mw._root().wm_title("Line clipping (Cohen-Sutherland Algorithm)")
# create and position canvas and buttons
cFr = Frame(mw, width=WIDTH, height=HEIGHT, relief="sunken", bd=1)
cFr.pack(side="top")
can = Canvas(cFr, width=WIDTH, height=HEIGHT)
can.bind("<Button-1>",mouseEvent)
can.pack()
cFr = Frame(mw)
cFr.pack(side="left")
bClear = Button(cFr, text="Clear", command=clearAll)
bClear.pack(side="left")
eFr = Frame(mw)
eFr.pack(side="right")
bExit = Button(eFr, text="Quit", command=(lambda root=mw: quit(root)))
bExit.pack()
# start
mw.mainloop()
示例14: return
return (beta_gamma,alpha_gamma)
# in this definition is the repaint of the triangle and the decision if is a --
# green or red dot
def clicked_point(event):
canv.delete(ALL)
trian(a,b,c)
x0 = event.x
y0 = event.y
p = complex(x0,y0)
x = faktor(p)
if (( 1>= x[0][0] >=0) and (x[0][1]>=0)):
canv.create_oval(x0-4,y0-4,x0+4,y0+4,fill='green')
else:
if (( 1>= x[1][0] >=0) and (x[1][1]>=0)):
canv.create_oval(x0-4,y0-4,x0+4,y0+4,fill='green')
else:
canv.create_oval(x0-4,y0-4,x0+4,y0+4,fill='red')
root = Tk()
canv = Canvas(root,width=size,height=size)
trian(a,b,c)
canv.bind("<Button-1>",clicked_point)
canv.bind("<B1-Motion>",clicked)
canv.pack()
root.mainloop()
示例15: fft
k = fft(x)
# definition to calculat the kinetic energie in the k-room
def B(k,t):
return exp(t*complex(0.,1.)*k*k/2.)
# definition to calculate the potential in the real room
def pot(x):
return pow(abs(x*x-1),2)/2.
def A(x,t):
return exp(t*complex(0.,1.)*(pot(x))/2.)
screen = Tk()
wd,ht = screen.winfo_screenwidth(),screen.winfo_screenheight()
screen.geometry("%dx%d+0+0"%(wd,ht))
canv = Canvas(screen,height=ht,width=wd,background="black")
canv.pack()
# some scale factor to enlarge the animation
scaley = 150
scalex = 140
# define the time
for t in linspace(0.1,0.5,2000):
# calculate A and B
expA = map(lambda x: A(x,t),x)
expB = map(lambda k: B(k,t),k)
# tranform back the k-room into the real room
expB = ifft(expB)
# calculate the time depended hamiltonien