当前位置: 首页>>代码示例>>Python>>正文


Python Group.addtag_withtag方法代码示例

本文整理汇总了Python中Canvas.Group.addtag_withtag方法的典型用法代码示例。如果您正苦于以下问题:Python Group.addtag_withtag方法的具体用法?Python Group.addtag_withtag怎么用?Python Group.addtag_withtag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Canvas.Group的用法示例。


在下文中一共展示了Group.addtag_withtag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Canvas import Group [as 别名]
# 或者: from Canvas.Group import addtag_withtag [as 别名]
class Pile:

    """A group of graphical objects."""

    def __init__(self, canvas, x, y, tag=None):
        self.canvas = canvas
        self.x = x
        self.y = y
        self.objects = []
        self.bottom = Bottom(self.canvas, self.x, self.y)
        self.group = Group(self.canvas, tag=tag)
        self.group.addtag_withtag(self.bottom.group)
        self.bindhandlers()

    def bindhandlers(self):
        self.group.bind('<1>', self.clickhandler)
        self.group.bind('<Double-1>', self.doubleclickhandler)

    def add(self, object):
        self.objects.append(object)
        self.group.addtag_withtag(object.group)
        self.position(object)

    def delete(self, object):
        object.group.dtag(self.group)
        self.objects.remove(object)

    def position(self, object):
        object.tkraise()
        i = self.objects.index(object)
        object.moveto(self.x + i*4, self.y + i*8)

    def clickhandler(self, event):
        pass

    def doubleclickhandler(self, event):
        pass
开发者ID:taoqsun,项目名称:DemoPythonCode,代码行数:39,代码来源:canvasevents.py

示例2: piles

# 需要导入模块: from Canvas import Group [as 别名]
# 或者: from Canvas.Group import addtag_withtag [as 别名]
class Object:

    """Base class for composite graphical objects.

    Objects belong to a canvas, and can be moved around on the canvas.
    They also belong to at most one ``pile'' of objects, and can be
    transferred between piles (or removed from their pile).

    Objects have a canonical ``x, y'' position which is moved when the
    object is moved.  Where the object is relative to this position
    depends on the object; for simple objects, it may be their center.

    Objects have mouse sensitivity.  They can be clicked, dragged and
    double-clicked.  The behavior may actually determined by the pile
    they are in.

    All instance attributes are public since the derived class may
    need them.

    """

    def __init__(self, canvas, x=0, y=0, fill='red', text='object'):
        self.canvas = canvas
        self.x = x
        self.y = y
        self.pile = None
        self.group = Group(self.canvas)
        self.createitems(fill, text)

    def __str__(self):
        return str(self.group)

    def createitems(self, fill, text):
        self.__oval = Oval(self.canvas,
                           self.x-20, self.y-10, self.x+20, self.y+10,
                           fill=fill, width=3)
        self.group.addtag_withtag(self.__oval)
        self.__text = CanvasText(self.canvas,
                           self.x, self.y, text=text)
        self.group.addtag_withtag(self.__text)

    def moveby(self, dx, dy):
        if dx == dy == 0:
            return
        self.group.move(dx, dy)
        self.x = self.x + dx
        self.y = self.y + dy

    def moveto(self, x, y):
        self.moveby(x - self.x, y - self.y)

    def transfer(self, pile):
        if self.pile:
            self.pile.delete(self)
            self.pile = None
        self.pile = pile
        if self.pile:
            self.pile.add(self)

    def tkraise(self):
        self.group.tkraise()
开发者ID:taoqsun,项目名称:DemoPythonCode,代码行数:63,代码来源:canvasevents.py

示例3: stacks

# 需要导入模块: from Canvas import Group [as 别名]
# 或者: from Canvas.Group import addtag_withtag [as 别名]
class Stack:

    """A generic stack of cards.

    This is used as a base class for all other stacks (e.g. the deck,
    the suit stacks, and the row stacks).

    Public methods:

    add(card) -- add a card to the stack
    delete(card) -- delete a card from the stack
    showtop() -- show the top card (if any) face up
    deal() -- delete and return the top card, or None if empty

    Method that subclasses may override:

    position(card) -- move the card to its proper (x, y) position

        The default position() method places all cards at the stack's
        own (x, y) position.

    userclickhandler(), userdoubleclickhandler() -- called to do
    subclass specific things on single and double clicks

        The default user (single) click handler shows the top card
        face up.  The default user double click handler calls the user
        single click handler.

    usermovehandler(cards) -- called to complete a subpile move

        The default user move handler moves all moved cards back to
        their original position (by calling the position() method).

    Private methods:

    clickhandler(event), doubleclickhandler(event),
    motionhandler(event), releasehandler(event) -- event handlers

        The default event handlers turn the top card of the stack with
        its face up on a (single or double) click, and also support
        moving a subpile around.

    startmoving(event) -- begin a move operation
    finishmoving() -- finish a move operation

    """

    def __init__(self, x, y, game=None):
        """Stack constructor.

        Arguments are the stack's nominal x and y position (the top
        left corner of the first card placed in the stack), and the
        game object (which is used to get the canvas; subclasses use
        the game object to find other stacks).

        """
        self.x = x
        self.y = y
        self.game = game
        self.cards = []
        self.group = Group(self.game.canvas)
        self.group.bind('<1>', self.clickhandler)
        self.group.bind('<Double-1>', self.doubleclickhandler)
        self.group.bind('<B1-Motion>', self.motionhandler)
        self.group.bind('<ButtonRelease-1>', self.releasehandler)
        self.makebottom()

    def makebottom(self):
        pass

    def __repr__(self):
        """Return a string for debug print statements."""
        return "%s(%d, %d)" % (self.__class__.__name__, self.x, self.y)

    # Public methods

    def add(self, card):
        self.cards.append(card)
        card.tkraise()
        self.position(card)
        self.group.addtag_withtag(card.group)

    def delete(self, card):
        self.cards.remove(card)
        card.group.dtag(self.group)

    def showtop(self):
        if self.cards:
            self.cards[-1].showface()

    def deal(self):
        if not self.cards:
            return None
        card = self.cards[-1]
        self.delete(card)
        return card

    # Subclass overridable methods

    def position(self, card):
#.........这里部分代码省略.........
开发者ID:atlsig,项目名称:Solitaire,代码行数:103,代码来源:solitaire.py

示例4: this

# 需要导入模块: from Canvas import Group [as 别名]
# 或者: from Canvas.Group import addtag_withtag [as 别名]
class Card:

    """A playing card.

    A card doesn't record to which stack it belongs; only the stack
    records this (it turns out that we always know this from the
    context, and this saves a ``double update'' with potential for
    inconsistencies).

    Public methods:

    moveto(x, y) -- move the card to an absolute position
    moveby(dx, dy) -- move the card by a relative offset
    tkraise() -- raise the card to the top of its stack
    showface(), showback() -- turn the card face up or down & raise it

    Public read-only instance variables:

    suit, value, color -- the card's suit, value and color
    face_shown -- true when the card is shown face up, else false

    Semi-public read-only instance variables (XXX should be made
    private):

    group -- the Canvas.Group representing the card
    x, y -- the position of the card's top left corner

    Private instance variables:

    __back, __rect, __text -- the canvas items making up the card

    (To show the card face up, the text item is placed in front of
    rect and the back is placed behind it.  To show it face down, this
    is reversed.  The card is created face down.)

    """

    def __init__(self, suit, value, canvas):
        """Card constructor.

        Arguments are the card's suit and value, and the canvas widget.

        The card is created at position (0, 0), with its face down
        (adding it to a stack will position it according to that
        stack's rules).

        """
        self.suit = suit
        self.value = value
        self.color = COLOR[suit]
        self.face_shown = 0

        self.x = self.y = 0
        self.group = Group(canvas)

        text = "%s  %s" % (VALNAMES[value], suit)
        self.__text = CanvasText(canvas, CARDWIDTH/2, 0,
                               anchor=N, fill=self.color, text=text)
        self.group.addtag_withtag(self.__text)

        self.__rect = Rectangle(canvas, 0, 0, CARDWIDTH, CARDHEIGHT,
                              outline='black', fill='white')
        self.group.addtag_withtag(self.__rect)

        self.__back = Rectangle(canvas, MARGIN, MARGIN,
                              CARDWIDTH-MARGIN, CARDHEIGHT-MARGIN,
                              outline='black', fill='blue')
        self.group.addtag_withtag(self.__back)

    def __repr__(self):
        """Return a string for debug print statements."""
        return "Card(%r, %r)" % (self.suit, self.value)

    def moveto(self, x, y):
        """Move the card to absolute position (x, y)."""
        self.moveby(x - self.x, y - self.y)

    def moveby(self, dx, dy):
        """Move the card by (dx, dy)."""
        self.x = self.x + dx
        self.y = self.y + dy
        self.group.move(dx, dy)

    def tkraise(self):
        """Raise the card above all other objects in its canvas."""
        self.group.tkraise()

    def showface(self):
        """Turn the card's face up."""
        self.tkraise()
        self.__rect.tkraise()
        self.__text.tkraise()
        self.face_shown = 1

    def showback(self):
        """Turn the card's face down."""
        self.tkraise()
        self.__rect.tkraise()
        self.__back.tkraise()
        self.face_shown = 0
开发者ID:atlsig,项目名称:Solitaire,代码行数:102,代码来源:solitaire.py

示例5:

# 需要导入模块: from Canvas import Group [as 别名]
# 或者: from Canvas.Group import addtag_withtag [as 别名]
#! /usr/bin/env python
开发者ID:mcyril,项目名称:ravel-ftn,代码行数:3,代码来源:solitaire.py


注:本文中的Canvas.Group.addtag_withtag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。