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


Python Canvas.pack方法代码示例

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


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

示例1: clear_can

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def clear_can():
    """
    캔버스를 초기화 하는 버튼명령
    """
    global can, tx_counter, count
    can.destroy()
    can = Canvas(frame_left, width=400, height=400, bg="#FFFFFF")
    tx_counter = can.create_text(20, 10, text="0")
    can.pack()
    count = 0
开发者ID:soma0sd,项目名称:python-study,代码行数:12,代码来源:03_button.py

示例2: initUI

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
    def initUI(self):
      
        self.parent.title("Colors")        
        self.pack(fill=BOTH, expand=1)

        canvas = Canvas(self)

        #bounds = canvas.bbox(canvas)  # returns a tuple like (x1, y1, x2, y2)
        #width = canvas.width #bounds[2] - bounds[0]
        #height = canvas.height #bounds[3] - bounds[1]

        size = len(self.dataXArray)

        graphHeight = 100
        graphOriginX = 0
        graphOriginY = self.canvasHeight / 2
        graphScaleX = self.canvasWidth / size

        #canvas.create_line(graphOriginX, graphOriginY - int(graphHeight), graphOriginX + (graphScaleX * (size + 1)), graphOriginY - int(graphHeight), fill="black")
        #canvas.create_line(graphOriginX, graphOriginY + int(graphHeight), graphOriginX + (graphScaleX * (size + 1)), graphOriginY + int(graphHeight), fill="black")
        canvas.create_line(graphOriginX, graphOriginY, graphOriginX + (graphScaleX * (size + 1)), graphOriginY, fill="black")
                

        for i in range(0, len(self.zippedDataArray) - 1):
            canvas.create_line(graphOriginX + (graphScaleX * i), graphOriginY - int(graphHeight * self.dataXArray[i]), graphOriginX + (graphScaleX * (i + 1)), graphOriginY - int(graphHeight * self.dataXArray[i + 1]), fill="red")
            canvas.create_line(graphOriginX + (graphScaleX * i), graphOriginY - int(graphHeight * self.dataYArray[i]), graphOriginX + (graphScaleX * (i + 1)), graphOriginY - int(graphHeight * self.dataYArray[i + 1]), fill="green")
            canvas.create_line(graphOriginX + (graphScaleX * i), graphOriginY - int(graphHeight * self.dataZArray[i]), graphOriginX + (graphScaleX * (i + 1)), graphOriginY - int(graphHeight * self.dataZArray[i + 1]), fill="blue")
            if i % 10 == 0 and self.drawVerticals:
                canvas.create_line(graphOriginX + (graphScaleX * i), graphOriginY - int(graphHeight), graphOriginX + (graphScaleX * (i)), graphOriginY + int(graphHeight), fill="black")



#        canvas.create_rectangle(270, 10, 370, 80, 
#            outline="#05f", fill="#05f")            
        canvas.pack(fill=BOTH, expand=1)
开发者ID:ProjPossibility,项目名称:2014-USC-CareTaker-3,代码行数:37,代码来源:AccelViz.py

示例3: main

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def main():
    root = Tk(className="My graphics!")
    root.geometry("400x400")
    canvas = Canvas()
    canvas.pack(fill=BOTH, expand=1)
    # img = draw_gradient(canvas)

    img = draw_danger_levels(canvas, 50, 50)

    # что бы ограничить число
    # if n > 255:
    #     n = 255

    # хочу: n = 256 => 0
    # n = 257 => 1
    # ...
    # n = 300 => 44
    # 10 // 3 = 3(1)
    # 10 - (10 // 3) * 3
    # 10 % 3
    # a % b < b
    # 10 % 3 = 1
    # 11 % 3 = 2
    # 12 % 3 = 0
    # 13 % 3 = 1

    root.mainloop()
开发者ID:AndrewLvov,项目名称:DrawTkinter,代码行数:29,代码来源:main.py

示例4: Main

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
class Main(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.info = {}
        self.window = None
        self.size = (640, 480)
        self.fields = []
        self.init_ui()

    def init_ui(self):
        self.parent.title("Node Writer")
        self.style = Style()
        self.style.theme_use("alt")
        self.pack(fill="both", expand=True)

        menubar = Menu(self.parent)
        self.parent.config(menu=menubar)
        menubar.add_command(label="New", command=self.onNew)
        menubar.add_command(label="Show Info", command=self.get_info)
        menubar.add_command(label="Exit", command=self.quit)

        self.canvas = Canvas(self, background="white", width=self.size[0], height=self.size[1])
        self.canvas.pack(fill="both", expand=1)
        self.canvas.bind("<Motion>", self.move_boxes)

    def move_boxes(self, event):
        print(event.x, event.y)
        """
        x, y = (event.x-1, event.y-1)
        x1, y1, x2, y2 = self.canvas.bbox("test")
        if x > x1 and y > y1 and x < x2 and y < y2:
            print("Hit")
        else:
            print("Missed")
        """

    def onNew(self):
        new = Node(self, "Node_entry")
        label = new.insert_entry_field("Labels")
        label2 = new.insert_entry_field("Labels2")
        text = new.insert_text_field("Text")
        new.ok_cancel_buttons()

    def get_info(self):
        x, y = (self.size[0]/2, self.size[1]/2)
        for i in self.info:
            label_frame= LabelFrame(self, text="name")
            label_frame.pack(fill="y")
            for entry in self.info[i]["Entry"]:
                frame = Frame(label_frame)
                frame.pack(fill="x")
                label = Label(label_frame, text=self.info[i]["Entry"][entry], width=6)
                label.pack(side="left", anchor="n", padx=5, pady=5)
            for text in self.info[i]["Text"]:
                frame = Frame(label_frame)
                frame.pack(fill="x")
                label = Label(label_frame, text=self.info[i]["Text"][text], width=6)
                label.pack(side="left", anchor="n", padx=5, pady=5)
        window = self.canvas.create_window(x, y, window=label_frame, tag="test")
开发者ID:Exodus111,项目名称:Projects,代码行数:62,代码来源:main.py

示例5: main

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def main():
    # Basic starter code.
    window = tkinter.Tk()
    canvas = Canvas(window, width = CANVAS_SIZE, height = CANVAS_SIZE)
    canvas.pack()
    
    draw_shaky_line(canvas, 50, 50, 650, 650)
开发者ID:minsun09,项目名称:volo_mission,代码行数:9,代码来源:mapline.py

示例6: TkWindowMainLoop

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
class TkWindowMainLoop(Thread):
    '''class for thread that handles Tk window creation and main loop''' 
    
    def __init__(self, client):
        Thread.__init__(self)
        
        self.window = None
        self.canvas = None
        self.client = client
        
        self.start()

    
    def callbackDeleteWindow(self):
        self.client.stop()
        
    def stop(self):
        self.window.quit()
        
    
    def run(self):
        self.window = Tk()
        self.canvas = Canvas(self.window, width=1024, height=768)
        self.canvas.pack()
        
        self.window.protocol("WM_DELETE_WINDOW", self.callbackDeleteWindow)
        
        self.window.mainloop()

    def getWindow(self):
        return self.window
    
    def getCanvas(self):
        return self.canvas
开发者ID:IwfY,项目名称:TkStein3d,代码行数:36,代码来源:tkwindowmainloop.py

示例7: run_pinballview

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def run_pinballview(width, height, configuration):
    """

        Changed from original Pierre-Luc Bacon implementation to reflect
        the visualization changes in the PinballView Class.

    """
    width, height = float(width), float(height)
    master = Tk()
    master.title('RLPY Pinball')
    screen = Canvas(master, width=500.0, height=500.0)
    screen.configure(background='LightGray')
    screen.pack()

    environment = PinballModel(configuration)
    environment_view = PinballView(screen, width, height, environment)

    actions = [
        PinballModel.ACC_X,
        PinballModel.DEC_Y,
        PinballModel.DEC_X,
        PinballModel.ACC_Y,
        PinballModel.ACC_NONE]
    done = False
    while not done:
        user_action = np.random.choice(actions)
        environment_view.blit()
        if environment.episode_ended():
            done = True
        if environment.take_action(user_action) == environment.END_EPISODE:
            done = True

        environment_view.blit()
        screen.update()
开发者ID:okkhoy,项目名称:rlpy,代码行数:36,代码来源:Pinball.py

示例8: draw_automata

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def draw_automata(turing_machine=None):

    w = len(turing_machine.states)
    h = len(turing_machine.rules)

    root = Tk()
    frame = Frame(root, width=800, height=600)
    frame.grid(row=0, column=0)
    canvas = Canvas(frame, bg='#FFFFFF', width=800, height=600,
                    scrollregion=(0, -h * 15, w * 100, h * 15*3))
    hbar = Scrollbar(frame, orient=HORIZONTAL)
    hbar.pack(side=BOTTOM, fill=X)
    hbar.config(command=canvas.xview)
    vbar = Scrollbar(frame, orient=VERTICAL)
    vbar.pack(side=RIGHT, fill=Y)
    vbar.config(command=canvas.yview)
    canvas.config(width=800, height=600)
    canvas.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set)
    canvas.pack(side=LEFT, expand=True, fill=BOTH)

    for position, state in enumerate(turing_machine.states):
        state_position[state] = position
        loop_occurrences[position] = 0
        canvas_id = canvas.create_text(10 + 80 * position, 400, anchor="nw")
        canvas.itemconfig(canvas_id, text="state-")
        canvas.insert(canvas_id, 12, "%d" % state)

    counter = 1
    for rule in turing_machine.rules:
        counter = draw_arrow(state_position[rule.current_state],
                             state_position[rule.next_state],
                             canvas, counter, rule)

    root.mainloop()
开发者ID:ytsvetkov,项目名称:TuringMachine,代码行数:36,代码来源:automata_graph.py

示例9: create_single_swiss

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def create_single_swiss(players,main):
    def create_plate(x,y,name):
        c.create_text(x+37,y+15,text=name)
        c.create_rectangle(x,y,x+75,y+25)
        c.create_line(x+75,y+12,x+85,y+12)

    destroy_all(main)
    c = Canvas(main)
    c.pack(fill=BOTH, expand=YES)

    shuffle(players)
    odd = False
    if(len(players)%2):
        odd = True

    i=int(ceil(len(players)/2))
    j=0;
    for x in range(i):
        if not odd:
            create_plate(25,25+x*75,players[j])
            j=j+1
            create_plate(25,55+x*75,players[j])
            j=j+1
            c.create_line(110,37+(x*75),110,67+(x*75))
        else:
            if j == i:
                create_plate(150,25+x*75,players[-1])
                break
            create_plate(25,25+x*75,players[j])
            j=j+1
            create_plate(25,55+x*75,players[j])
            j=j+1
            c.create_line(110,37+(x*75),110,67+(x*75))
开发者ID:MajorTom6,项目名称:libreswiss,代码行数:35,代码来源:create_single_swiss.py

示例10: Wall

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
class Wall(object):
    MIN_RED = MIN_GREEN = MIN_BLUE = 0x0
    MAX_RED = MAX_GREEN = MAX_BLUE = 0xFF

    PIXEL_WIDTH = 50

    def __init__(self, width, height):
        self.width = width
        self.height = height
        self._tk_init()
        self.pixels = [(0, 0, 0) for i in range(self.width * self.height)]

    def _tk_init(self):
        self.root = Tk()
        self.root.title("ColorWall %d x %d" % (self.width, self.height))
        self.root.resizable(0, 0)
        self.frame = Frame(self.root, bd=5, relief=SUNKEN)
        self.frame.pack()

        self.canvas = Canvas(self.frame,
                             width=self.PIXEL_WIDTH * self.width,
                             height=self.PIXEL_WIDTH * self.height,
                             bd=0, highlightthickness=0)
        self.canvas.pack()
        self.root.update()

    def set_pixel(self, x, y, hsv):
        self.pixels[self.width * y + x] = hsv

    def get_pixel(self, x, y):
        return self.pixels[self.width * y + x]

    def draw(self):
        self.canvas.delete(ALL)
        for x in range(len(self.pixels)):
            x_0 = (x % self.width) * self.PIXEL_WIDTH
            y_0 = (x / self.width) * self.PIXEL_WIDTH
            x_1 = x_0 + self.PIXEL_WIDTH
            y_1 = y_0 + self.PIXEL_WIDTH
            hue = "#%02x%02x%02x" % self._get_rgb(self.pixels[x])
            self.canvas.create_rectangle(x_0, y_0, x_1, y_1, fill=hue)
        self.canvas.update()

    def clear(self):
        for i in range(self.width * self.height):
            self.pixels[i] = (0, 0, 0)

    def _hsv_to_rgb(self, hsv):
        rgb = colorsys.hsv_to_rgb(*hsv)
        red = self.MAX_RED * rgb[0]
        green = self.MAX_GREEN * rgb[1]
        blue = self.MAX_BLUE * rgb[2]
        return (red, green, blue)

    def _get_rgb(self, hsv):
        red, green, blue = self._hsv_to_rgb(hsv)
        red = int(float(red) / (self.MAX_RED - self.MIN_RED) * 0xFF)
        green = int(float(green) / (self.MAX_GREEN - self.MIN_GREEN) * 0xFF)
        blue = int(float(blue) / (self.MAX_BLUE - self.MIN_BLUE) * 0xFF)
        return (red, green, blue)
开发者ID:rkedge,项目名称:ColorWall,代码行数:62,代码来源:wall.py

示例11: __init__

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
    def __init__(self, drs, size_canvas=True, canvas=None):
        """
        :param drs: ``AbstractDrs``, The DRS to be drawn
        :param size_canvas: bool, True if the canvas size should be the exact size of the DRS
        :param canvas: ``Canvas`` The canvas on which to draw the DRS.  If none is given, create a new canvas.
        """
        master = None
        if not canvas:
            master = Tk()
            master.title("DRT")

            font = Font(family='helvetica', size=12)

            if size_canvas:
                canvas = Canvas(master, width=0, height=0)
                canvas.font = font
                self.canvas = canvas
                (right, bottom) = self._visit(drs, self.OUTERSPACE, self.TOPSPACE)

                width = max(right+self.OUTERSPACE, 100)
                height = bottom+self.OUTERSPACE
                canvas = Canvas(master, width=width, height=height)#, bg='white')
            else:
                canvas = Canvas(master, width=300, height=300)

            canvas.pack()
            canvas.font = font

        self.canvas = canvas
        self.drs = drs
        self.master = master
开发者ID:BohanHsu,项目名称:developer,代码行数:33,代码来源:drt.py

示例12: setUpCanvas

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def setUpCanvas(): 
  from tkinter import Tk, Canvas, YES, BOTH
  root = Tk()
  root.title("A Tk/Python Graphics Program")
  canvas = Canvas(root, width = 1270, height = 780, bg = 'black')
  canvas.pack(expand = YES, fill = BOTH)
  return canvas, root
开发者ID:changarno,项目名称:tjhsst1314,代码行数:9,代码来源:graphics.py

示例13: CameraView

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
class CameraView(View):
    def __init__(self, params):
        super(CameraView, self).__init__(params)

        self._multiplier = int(params["multiplier"]) if "multiplier" in params else 1
        self._multiplier = max(self._multiplier, 1)

        self._tk = Tk()
        self._canvas = Canvas(self._tk, width=80 * self._multiplier, height=60 * self._multiplier)

        self._tk.title("Camera view")
        self._tk.resizable(width=False, height=False)
        self._canvas.pack(side=tkinter.LEFT, fill=tkinter.BOTH, expand=True)

        self._tk.protocol("WM_DELETE_WINDOW", self.on_press_close)

        self._base_dir = "camera_" + str(int(time.time() * 1000))
        os.makedirs(self._base_dir)

    def run(self):
        super(CameraView, self).run()
        self._tk.mainloop()

    def on_new_input(self):
        try:
            hex_str = self.get_input()
            img = self._get_image(hex_str)
        except Exception as e:
            logging.debug(str(e))
            return
        if img is None:
            return

        bmp = ImageTk.BitmapImage(image=img, foreground="white", background="black")
        self._canvas.create_image(0, 0, image=bmp, anchor=tkinter.NW)
        self._tk_image = bmp

        img.save(self._base_dir + "/" + str(int(time.time() * 1000)) + ".png")

    def on_dismiss(self):
        self._tk.after_idle(self.on_press_close)

    def on_press_close(self):
        self._tk.destroy()
        self.join_io_thread()

    def _get_image(self, hex_str) -> Image:
        try:
            hex_data = binascii.unhexlify(hex_str)
            # Invert data from MCU
            hex_data = bytes([~h & 0xFF for h in hex_data])
        except TypeError as e:
            logging.debug(str(e))
            return

        img = Image.frombytes(mode="1", size=(80, 60), data=hex_data)
        img = img.resize((80 * self._multiplier, 60 * self._multiplier))
        return img
开发者ID:hkust-smartcar,项目名称:sc-studio,代码行数:60,代码来源:camera_view.py

示例14: build

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
 def build(self):
     width = self.hardware.get('x') * LCD.SCREEN_SCALE
     height = self.hardware.get('y') * LCD.SCREEN_SCALE
     skin_position = self.hardware.get('skin_position')
     if skin_position == 'Y':
         width, height = height, width
     canvas = Canvas(self.master, width=width, height=height)
     canvas.pack()
     self.widget = canvas
开发者ID:alej0varas,项目名称:pybolator,代码行数:11,代码来源:pybgui.py

示例15: main

# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import pack [as 别名]
def main():
    root = Tk()
    canvas = Canvas(root, bg='white', width=720, height=900)
    canvas.pack()
    
    map1 = Map()
    map1.drawMap(canvas)
    
    root.mainloop()
开发者ID:greenfox-velox,项目名称:attilakrupl,代码行数:11,代码来源:main.py


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