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


Python Canvas.create_oval方法代码示例

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


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

示例1: C_circle

# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import create_oval [as 别名]
def C_circle(args):
    Canvas.create_oval(cursor_pos[0]-int(args[0]), cursor_pos[1]-int(args[0]), cursor_pos[0]+int(args[0]), cursor_pos[1]+int(args[0]))
开发者ID:vipuldivyanshu92,项目名称:Projects,代码行数:4,代码来源:task3.py

示例2: SudokuUI

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

示例3: Plot

# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import create_oval [as 别名]

#.........这里部分代码省略.........
            # get the value with the index 2 in each row
            for item in row[2]:

                for row in values:
                    endValue = row
                    
                    # setting zeroTotal to zero
                    xZero = xZeroTotal
                    yZero = yZeroTotal
                    # setting point to zero for the reason the line begins at the zero point
                    xPoint = xZero
                    yPoint = yZero                    

                    
                    # write xValue an yValue for the right selection
                    for row in endValue:
                        if item[0] == '1':
                            xValue = row[0]
                            yValue = row[6] 
                        elif item[0] == '2':
                            xValue = row[0]
                            yValue = row[7]
                        elif item[0] == '3':
                            xValue = row[1]
                            yValue = row[6]
                        elif item[0] == '4':
                            xValue = row[1]
                            yValue = row[7] 
                        elif item[0] == '5':
                            xValue = row[2]
                            yValue = row[6]
                        elif item[0] == '6':
                            xValue = row[2]
                            yValue = row[7]                                                                                                                                        
                        else:
                            pass
                        
                        # setting color for the line
                        color = colors[idx][int(item[0]) - 1]
                        
                        # calculating x,y points on the screen
                        xPoint = (xValue * self.dist_x) + 70
                        yPoint = self.sh - ((yValue * self.dist_y) + 150) * self.win_osx_factor
                        
                        # drawing line
                        self.canvas.create_line(xZero, yZero, xPoint, yPoint, fill=color, width = 3, tag = "plot")

                        self.canvas.create_oval(xPoint - 4, yPoint - 4, xPoint + 4, yPoint + 4, fill = color, outline = color, tag = "plot")
                        
                        # setting x,y points as new zero points
                        xZero = xPoint
                        yZero = yPoint
                        

        
    def createlist(self, idx):
        '''
        adding new index to the list with two empty fields
        '''
        self.value_list.append([idx])
        self.value_list[idx].append(None)
        self.value_list[idx].append(None)
        


        
        
        
    def getMax(self, value_list):
        '''
        This method is trying to find the max value for the scale grid.
        '''
        # setting max values to zero to find out the highest value
        self.xMax = 0
        self.yMax = 0

                        
        # get values
        for row in value_list:
            values = row[1]
            for row in values:
                endValue = row
                for row in endValue: 
                    
                    # check for max value in the x-axis                                                 
                    for i in range(1,3):
                        if self.xMax < row[i]:
                            self.xMax = row[i]
                    
                    # check for max value in the y-axis
                    for i in range(6,7):
                        if self.yMax < row[i]:
                            self.yMax = row[i]


        # calculating the distance between     
        self.dist_x = (self.sw - 400) / self.xMax
        self.dist_y = (self.sh - 500) / self.yMax       
        self.createCoordSystem()
        
开发者ID:nebelriss,项目名称:FluidX,代码行数:103,代码来源:plot.py

示例4: Ccircle

# 需要导入模块: import Canvas [as 别名]
# 或者: from Canvas import create_oval [as 别名]
def Ccircle(args):                                                  # Command called when circle is called
    print 'draw a circle with radius %d' % (args[0])                #debug
    # If the cursor is the centre then to draw it we need to find
    # the corners of the containg box, so just remove/add the radius
    # to the x and y axis
    Canvas.create_oval(cpos[0]-args[0], cpos[1]-args[0], cpos[0]+args[0], cpos[1]+args[0])
开发者ID:vipuldivyanshu92,项目名称:Projects,代码行数:8,代码来源:main.py


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