本文整理汇总了Python中tkinter.Canvas.itemconfigure方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.itemconfigure方法的具体用法?Python Canvas.itemconfigure怎么用?Python Canvas.itemconfigure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.itemconfigure方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: margin
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import itemconfigure [as 别名]
#.........这里部分代码省略.........
def refreshScore(self):
"""Visually updates the score reached by the user: actually it
just changes the window title :P
"""
self.updateTitle(str(self.onBoard) + " / " + str(self.expectedBest))
def checkAvailable(self, x, y):
"""Checks if the cell at (x, y) is on the board AND is not busy
"""
return 0 <= x < self.rows and 0 <= y < self.cols and not self.gridBusy[x][y]
def checkFree(self, x, y):
"""Checks whether the position (x, y) is available or not.
Returns the color to use for the background ('busy' or 'free')
"""
for i in range(self.numPieces):
new_x = x + self.pos[self.rotation][i][0]
new_y = y + self.pos[self.rotation][i][1]
if not self.checkAvailable(new_x, new_y):
return self.colors['busy']
return self.colors['free']
def doPaint(self, x, y, color, pattern=""):
"""Does the actual painting: it paints with the specified color
and pattern the background at (x, y). If a pattern isn't
specified it won't be used
"""
for i in range(self.numPieces):
new_x = x + self.pos[self.rotation][i][0]
new_y = y + self.pos[self.rotation][i][1]
if 0 <= new_x < self.rows and 0 <= new_y < self.cols:
for item in self.gridBG[new_x][new_y][0]:
self.canvas.itemconfigure(item, fill=color, stipple=pattern)
def correctPending(self):
"""Restores to the normal state the last painted background
"""
if self.lastPainted:
self.doPaint(self.lastPainted[0], self.lastPainted[1], self.colors['idle'], "gray75")
self.lastPainted = None
def paintBackground(self, x, y, color):
"""Updates background to visually indicate whether the position
(x, y) is available or not
"""
self.correctPending()
self.lastPainted = (x, y)
self.doPaint(x, y, color)
def mouseOut(self, event):
"""Catch mouseout in order to clean the last background painted
when the cursor leaves the grid
"""
if self.editMode and self.lastChanged:
self.changeColor(self.lastChanged, self.colors['pentomino'])
return
self.correctPending()
self.lastPosition = None
def mouseOver(self, event):
"""Catch mouseover to paint the background accordingly to the
availability of the pentomino space under the cursor
"""
if self.editMode:
self.setEditCursor(event)
示例2: TKinterDisplay
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import itemconfigure [as 别名]
#.........这里部分代码省略.........
r2 = a2 * b2 / (math.sqrt(((a2 * a2) * (math.pow(math.sin(x2angle), 2))) + ((b2 * b2) * math.pow(math.cos(x2angle), 2))))
x1 = x1 + ((r1 / hyp) * (x2 - x1))
y1 = y1 + ((r1 / hyp) * (y2 - y1))
#x2 = x2 + ((r2 / hyp) * (x1 - x2))
#y2 = y2 - ((r2 / hyp) * (y1 - y2))
return self.__drawLine(x1, y1, x2, y2, tags, colour)
@abstractmethod
def renderTextInId(self, tagTocentreOn, tagsToAddTo, content, funcContent):
id1tuple = self.__getCoords(tagTocentreOn)
x1 = id1tuple[0] + ((id1tuple[2] - id1tuple[0]) / 2)
y1 = id1tuple[1] + ((id1tuple[3] - id1tuple[1]) / 2)
txt = self.__renderText(x1, y1, (id1tuple[2] - id1tuple[0]), content, tagsToAddTo)
def handler(event, self=self, content=funcContent):
return self.__eventOnClick(event, content)
self.localCanvas.tag_bind(txt, "<ButtonRelease-1>", handler)
return txt
@abstractmethod
def move(self, tag, xamount, yamount):
self.localCanvas.move(tag, xamount, yamount)
@abstractmethod
def runDisplay(self):
self.localCanvas.mainloop()
def __hideId(self, objectId):
self.localCanvas.itemconfigure(objectId, state="hidden")
pass
def __showId(self, objectId):
self.localCanvas.itemconfigure(objectId, state="normal")
pass
def __sampleDraw(self):
self.localCanvas.create_oval(0, 0, 0, 0, width=0)
def __renderText(self, x, y, width, content, tag):
val = self.localCanvas.create_text(x, y, width=width, text=content, tags=tag, justify="center", font="Helvetica 8 bold", anchor="center")
self.localCanvas.tag_raise(val)
return val
def __drawLine(self, x1, y1, x2, y2, tags=None, colour="black"):
line = self.localCanvas.create_line(x1, y1, x2, y2, tags=tags, width=self.lineThickness, arrow="first", arrowshape=(16,20,6),fill=colour, smooth=True)
self.localCanvas.tag_lower(line)
return # line
def __remove(self, num):
self.localCanvas.delete(num)
def __getCoords(self, ident):
return self.localCanvas.coords(ident)
def __eventOnFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
assert self.localCanvas
coord_tuple = self.localCanvas.bbox("all")
if not coord_tuple:
logging.error("Frame reconfigure error on coordinate acquire.")
else:
示例3: View
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import itemconfigure [as 别名]
class View():
def __init__(self, root, controller):
self.__controller = controller
root.wm_title("Bomber")
self.__windowsystem = root.call('tk', 'windowingsystem')
self.__frame = root
self.__canvas = Canvas(self.__frame, width=int(CANVAS_WIDTH),
height=int(CANVAS_HEIGHT), bg="white")
self.__canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
self.__init_fonts()
self.__init_arena()
self.__init_score()
self.__block_views = [] # type: List[BlockView]
self.__blockfield_view = BlockfieldView()
self.__messages = []
def __init_fonts(self):
self.bigfont = font.nametofont("TkDefaultFont")
self.bigfont.configure(size=int(48))
self.scorefont = font.nametofont("TkDefaultFont")
self.scorefont.configure(size=int(20))
def __init_score(self):
self.score_text = self.__canvas.create_text(5, 5, anchor="nw")
self.__canvas.itemconfig(self.score_text, text="Score:", font=self.scorefont)
def __init_arena(self):
self.__canvas.create_rectangle(LEFT_OFFSET, TOP_OFFSET,
LEFT_OFFSET + MAXCOL*GRID_SIZE,
TOP_OFFSET+MAXROW*GRID_SIZE, fill="black")
nextblocktext = self.__canvas.create_text(GRID_SIZE,
TOP_OFFSET + GRID_SIZE * 4, anchor="nw")
self.__canvas.itemconfigure(nextblocktext, text="Next:",
font=self.bigfont, fill="black")
self.__autoplay_text = self.__canvas.create_text(LEFT_OFFSET + GRID_SIZE * 5,
TOP_OFFSET - GRID_SIZE, anchor="c")
self.__canvas.itemconfigure(self.__autoplay_text, text="Play mode",
font=self.bigfont, fill="black")
def register_block(self, block):
block_view = BlockView(block)
self.__block_views.append(block_view)
def unregister_block(self, block):
for block_view in self.__block_views:
if block_view.block is block:
block_view.erase(self.__canvas)
self.__block_views.remove(block_view)
def update_blockfield(self, blockfield):
self.__blockfield_view.redraw(self.__canvas, blockfield)
def display_score(self):
self.__canvas.itemconfig(self.score_text, text="Score: " + str(self.__controller.score),
font=self.scorefont)
def show_autoplay(self, autoplay):
if autoplay:
self.__canvas.itemconfig(self.__autoplay_text, text="Auto-play mode",
font=self.scorefont, fill="black")
else:
self.__canvas.itemconfig(self.__autoplay_text, text="Manual mode",
font=self.scorefont, fill="black")
def game_over(self):
text1 = self.__canvas.create_text(LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
CANVAS_HEIGHT/2, anchor="c")
text2 = self.__canvas.create_text(LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
CANVAS_HEIGHT/2 + 100, anchor="c")
text1_shadow = self.__canvas.create_text(2 + LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
2 + CANVAS_HEIGHT/2, anchor="c")
text2_shadow = self.__canvas.create_text(2 + LEFT_OFFSET + GRID_SIZE*MAXCOL//2,
2 + CANVAS_HEIGHT/2 + 100, anchor="c")
self.__messages.append(text1)
self.__messages.append(text2)
self.__messages.append(text1_shadow)
self.__messages.append(text2_shadow)
self.__canvas.itemconfig(text1, text="GAME OVER!",
font=self.bigfont, fill="white")
self.__canvas.itemconfig(text2, text="Press r to play again.",
font=self.scorefont, fill="white")
self.__canvas.itemconfig(text1_shadow, text="GAME OVER!",
font=self.bigfont, fill="black")
self.__canvas.itemconfig(text2_shadow, text="Press r to play again.",
font=self.scorefont, fill="black")
self.__canvas.tag_raise(text1)
self.__canvas.tag_raise(text2)
def clear_messages(self):
for txt in self.__messages:
self.__canvas.delete(txt)
self.__messages.clear()
def update(self):
for block_view in self.__block_views:
block_view.redraw(self.__canvas)
self.display_score()
示例4: TkLEDTableMixin
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import itemconfigure [as 别名]
class TkLEDTableMixin(object):
BACKGROUND_COLOR = "black"
BORDER_COLOR = "gray"
PIXEL_ORDER_COLOR = "white"
PIXEL_WIDTH = 30
PIXEL_HEIGHT = 30
PIXEL_BORDER = 1
def __init__(self, *args, **kw):
self._canvas = Canvas(self, width = 0, height = 0)
self._canvas.pack()
self._pixels = []
self._saved_pixels = []
self._pixel_order = []
self._pixel_width = self.PIXEL_WIDTH
self._pixel_height = self.PIXEL_HEIGHT
self._pixel_border = self.PIXEL_BORDER
self._height = self._width = 0
# initial configuration
@property
def width(self):
return self._width
@width.setter
def width(self, value):
self.dimensions = value, self.height
@property
def height(self):
return self._height
@height.setter
def height(self, value):
self.dimensions = self.width, value
@property
def dimensions(self):
return self._width, self._height
@dimensions.setter
def dimensions(self, value):
width, height = value
self._remove_all_pixels()
self._width, self._height = width, height
self._create_pixels()
# utility methods
def _create_pixels(self):
assert not self._pixels
for y in range(self.height):
pixels = []
self._pixels.append(pixels)
for x in range(self.width):
pixel = self._canvas.create_rectangle(0,0,1,1)
pixels.append(pixel)
self._update_configuration()
for y, row in enumerate(self._saved_pixels[:self.height]):
for x, color in enumerate(row[:self.width]):
self.set_pixel_color(x, y, color)
def _remove_all_pixels(self):
self._saved_pixels = [[self.get_pixel_color(x, y) for x in range(self.width)] for y in range(self.height)]
for pixel in self._all_pixels:
self._canvas.delete(pixel)
self._pixels = []
self._remove_pixel_order()
def _remove_pixel_order(self):
for line in self._pixel_order:
self._canvas.delete(line)
self._pixel_order = []
@property
def _all_pixels(self):
return chain.from_iterable(self._pixels)
def _update_configuration(self):
for y, row in enumerate(self._pixels):
for x, pixel in enumerate(row):
x_cor = x * self.pixel_width
y_cor = y * self.pixel_height
self._canvas.coords(pixel, x_cor, y_cor,
x_cor + self.pixel_width,
y_cor + self.pixel_height)
self._canvas.itemconfigure(pixel, outline = self.BORDER_COLOR,
fill = self.BACKGROUND_COLOR,
width = self.pixel_border)
self._canvas.configure(width = self.width * self.pixel_width,
height = self.height * self.pixel_height)
# pixel configuration
@property
def pixel_width(self):
return self._pixel_width
@pixel_width.setter
#.........这里部分代码省略.........