首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >附加到列表的图像或类

附加到列表的图像或类
EN

Stack Overflow用户
提问于 2020-12-14 02:47:17
回答 1查看 52关注 0票数 0

我一直试图通过让消息框出现来检测获胜者,我正在考虑将所有被销毁的作品附加到列表中,然后如果国王在那里,那么检测到获胜,我正在努力解决是否是类GUIKing或附加到列表中的作品的图像。

代码语言:javascript
复制
def destroy_piece(self, piece):
        """ Removes piece from the canvans and click-handler
            automatily called by move_piece
        """
        img1=piece.get_img_int(0)
        img2=piece.get_img_int(1)
        
        del self._on_clicks[str(img1)]
        del self._on_clicks[str(img2)]
        
        self.delete(piece.get_img_int(0))
        self.delete(piece.get_img_int(1))
        
        self.destroyed_pieces = [] 
        self.destroyed_pieces.append(piece)
EN

回答 1

Stack Overflow用户

发布于 2020-12-14 02:58:18

该列表应该包含一个对象,因此应该使用GUIKing类实例。但这取决于你如何在整个程序中做到这一点。你必须保持它的一致性,并且始终使用对象/类。这个比较好。

但为了快速修复,您可以使用以下代码:

代码语言:javascript
复制
def destroy_piece(self, piece):
        """ Removes piece from the canvans and click-handler
            automatily called by move_piece
        """
        img1=piece.get_img_int(0)
        img2=piece.get_img_int(1)
        
        del self._on_clicks[str(img1)]
        del self._on_clicks[str(img2)]
        
        self.delete(piece.get_img_int(0))
        self.delete(piece.get_img_int(1))
        
        ## self.destroyed_pieces = [] ## move this in the class __init__
        self.destroyed_pieces.append(piece)
        
        ##for elem in self.destroyed_pieces: ## remove this unneccessary line
        if "bk.png" or "wk.png" in self.destroyed_pieces:
            messagebox.showinfo("WINNER")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65279336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档