本文整理汇总了Python中Canvas.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.delete方法的具体用法?Python Canvas.delete怎么用?Python Canvas.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mozayik
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import delete [as 别名]
class Mozayik(QWidget):
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")
#print("mozayik size:")
#print(self.size())
def enterFolderContact(self):
self.viewer.openFolder()
def addTilesContact(self):
self.viewer.addTiles()
def deleteContact(self):
self.mozayik.delete()
def sizeHint(self):
return self.minimumSize()
def minimumSize(self):
size = QSize(16,9)
size.scale(700,700,Qt.KeepAspectRatioByExpanding)
#print("size hint for mozayik")
#print(size)
return size
示例2: Canvas
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import delete [as 别名]
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
y = expA*expB*expA
# i took the norm of phi because thr numbers get realy large with t
y = real(y)/max(abs(real(y)))
# draw the waves with lines
for i in range(len(y)-1):
y0=y[i]
y1=y[i+1]
x0=x[i]
x1=x[i+1]
canv.create_line(scalex*x0+650, 400+scaley*y0, scalex*x1+650, 400+scaley*y1,fill='red')
canv.update()
canv.delete(ALL)
screen.mainloop()
示例3: Plot
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import delete [as 别名]
class Plot(object):
'''
A canvas will be created where the selected values will be plotted as lines, with the best fitting scale.
Initial version by:
Michel Heiniger and Sandra Lang
Latest source code can be found at:
https://github.com/nebelriss/FluidX
'''
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
def createCoordSystem(self):
'''
This creates the coordinate system with a given max value for x,y axis.
'''
# Interval for the numbers
self.xInterval = 2
self.yInterval = 0.2
# delete all canvas with the tag "text"
self.canvas.delete("text")
# draw axis lines
self.canvas.create_line(self.sw-315, self.sh-150, 50, self.sh-150, fill = "black", width = 1)
self.canvas.create_line(70, self.sh-130, 70, 70, fill = "black", width = 1)
# text for Axis
y = 'Y-Axis'
x = 'X-Axis'
# write the text at the right position
self.canvas.create_text(70,40, text= y, tag = "text")
self.canvas.create_text(self.sw-315,self.sh-120, text= x, tag = "text")
# numbers for x and y axis
maximumx = ((self.xMax) + 2) / self.xInterval
maximumy = ((self.yMax) + 1) / self.yInterval
# loop to write the numbers under the axis line and draw the separation lines for the x-axis
for i in range(int(maximumx)):
x = 70 + (i * self.dist_x * self.xInterval)
self.canvas.create_line(x,self.sh-150,x,self.sh-155, width = 2)
self.canvas.create_text(x,self.sh-140, text='%d'% (i * self.xInterval), anchor=N, tag = "text")
# loop to write the numbers under the axis line and draw the separation lines for the x-axis
for i in range (int(maximumy)):
y = self.sh-150-(i * self.dist_y * self.yInterval) * self.win_osx_factor
self.canvas.create_line(70,y,75,y, width = 2)
self.canvas.create_text(45,y, text=str((i * self.yInterval)), anchor=W, tag = "text")
def createline (self, meta, values, idx, sel_idx, colors):
'''
Fist the given values are written in a list with the index number of the listbox and the selected items.
'''
# remove all lines with the tag "plot"
self.canvas.delete("plot")
# overwrite values with the given index with none
try:
self.value_list[idx][1] = None
except IndexError:
print "Index Error - List out of range"
#.........这里部分代码省略.........
示例4: SudokuUI
# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import delete [as 别名]
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
#.........这里部分代码省略.........