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


Python Canvas.bind方法代码示例

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


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

示例1: return

# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import bind [as 别名]
    
    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()

开发者ID:DordeMasovic,项目名称:Comp-Sci,代码行数:31,代码来源:traingel.py

示例2: draw

# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import bind [as 别名]
    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()
    
开发者ID:ccaspers,项目名称:college-practices,代码行数:32,代码来源:main.py

示例3: SudokuUI

# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import bind [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
#.........这里部分代码省略.........
开发者ID:More4me,项目名称:AI,代码行数:103,代码来源:GUI.py


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