Python Tkinter() Examples

The following are 30 code examples of Tkinter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Tkinter , or try the search function .
Example #1
Source File: pipark_setup.py    From PiPark with GNU General Public License v2.0 8 votes vote down vote up
def __createDisplay(self):
        """
        Create the display tkinter canvas to hold the images taken by the
        pi camera.
        
        """
        
        self.display = tk.Canvas(
            self, 
            width = s.PICTURE_RESOLUTION[0],
            height = s.PICTURE_RESOLUTION[1]
            )
        self.display.grid(row = 2, column = 0, rowspan = 1, columnspan = 6)


    # --------------------------------------------------------------------------
    #   Create Options Menu
    # -------------------------------------------------------------------------- 
Example #2
Source File: chart.py    From razzy-spinner with GNU General Public License v3.0 7 votes vote down vote up
def _sb_canvas(self, root, expand='y', 
                   fill='both', side='bottom'):
        """
        Helper for __init__: construct a canvas with a scrollbar.
        """
        cframe =Tkinter.Frame(root, relief='sunk', border=2)
        cframe.pack(fill=fill, expand=expand, side=side)
        canvas = Tkinter.Canvas(cframe, background='#e0e0e0')
        
        # Give the canvas a scrollbar.
        sb = Tkinter.Scrollbar(cframe, orient='vertical')
        sb.pack(side='right', fill='y')
        canvas.pack(side='left', fill=fill, expand='yes')

        # Connect the scrollbars to the canvas.
        sb['command']= canvas.yview
        canvas['yscrollcommand'] = sb.set

        return (sb, canvas) 
Example #3
Source File: mapeditor.py    From rgkit with The Unlicense 6 votes vote down vote up
def make_canvas(self):
        root = Tkinter.Tk()
        size = (self._blocksize + self._padding) * settings.board_size + \
            self._padding * 2 + 40

        self._canvas = Tkinter.Canvas(root, width=size, height=size)
        self._rect_items = []
        self._colors = []
        self._pressed = False

        self.prepare_backdrop(size)
        self.load_map()
        self.set_color('black')
        self.bind_events()

        self._canvas.pack()
        root.title('Robot Game Map Editor')
        root.mainloop() 
Example #4
Source File: turtle.py    From BinderFilter with MIT License 6 votes vote down vote up
def __forwardmethods(fromClass, toClass, toPart, exclude = ()):
    """Helper functions for Scrolled Canvas, used to forward
    ScrolledCanvas-methods to Tkinter.Canvas class.
    """
    _dict = {}
    __methodDict(toClass, _dict)
    for ex in _dict.keys():
        if ex[:1] == '_' or ex[-1:] == '_':
            del _dict[ex]
    for ex in exclude:
        if ex in _dict:
            del _dict[ex]
    for ex in __methods(fromClass):
        if ex in _dict:
            del _dict[ex]

    for method, func in _dict.items():
        d = {'method': method, 'func': func}
        if type(toPart) == types.StringType:
            execString = \
                __stringBody % {'method' : method, 'attribute' : toPart}
        exec execString in d
        fromClass.__dict__[method] = d[method] 
Example #5
Source File: thresholder.py    From mxnet-lambda with Apache License 2.0 6 votes vote down vote up
def __init__(self, master, im, value=128):
        tkinter.Frame.__init__(self, master)

        self.image = im
        self.value = value

        self.canvas = tkinter.Canvas(self, width=im.size[0], height=im.size[1])
        self.backdrop = ImageTk.PhotoImage(im)
        self.canvas.create_image(0, 0, image=self.backdrop, anchor=tkinter.NW)
        self.canvas.pack()

        scale = tkinter.Scale(self, orient=tkinter.HORIZONTAL, from_=0, to=255,
                              resolution=1, command=self.update_scale,
                              length=256)
        scale.set(value)
        scale.bind("<ButtonRelease-1>", self.redraw)
        scale.pack()

        # uncomment the following line for instant feedback (might
        # be too slow on some platforms)
        # self.redraw() 
Example #6
Source File: painter.py    From mxnet-lambda with Apache License 2.0 6 votes vote down vote up
def __init__(self, master, image):
        tkinter.Canvas.__init__(self, master,
                                width=image.size[0], height=image.size[1])

        # fill the canvas
        self.tile = {}
        self.tilesize = tilesize = 32
        xsize, ysize = image.size
        for x in range(0, xsize, tilesize):
            for y in range(0, ysize, tilesize):
                box = x, y, min(xsize, x+tilesize), min(ysize, y+tilesize)
                tile = ImageTk.PhotoImage(image.crop(box))
                self.create_image(x, y, image=tile, anchor=tkinter.NW)
                self.tile[(x, y)] = box, tile

        self.image = image

        self.bind("<B1-Motion>", self.paint) 
Example #7
Source File: __init__.py    From GeoVis with MIT License 6 votes vote down vote up
def _SaveRenderedShapefile(self, savepath):
        if RENDERER == "tkinter":
            raise AttributeError("The Tkinter map renderer does not have a function to save the map as an image \
due to the limited options of the Tkinter Canvas. If possible try using any of the other renderers instead")
        else:
            self.renderer.SaveImage(savepath)







############## FINALLY, DEFINE FRONT-END USER FUNCTIONS

#INTERACTIVE INPUT HELPERS 
Example #8
Source File: turtle.py    From BinderFilter with MIT License 6 votes vote down vote up
def __init__(self, master, width=500, height=350,
                                          canvwidth=600, canvheight=500):
        TK.Frame.__init__(self, master, width=width, height=height)
        self._rootwindow = self.winfo_toplevel()
        self.width, self.height = width, height
        self.canvwidth, self.canvheight = canvwidth, canvheight
        self.bg = "white"
        self._canvas = TK.Canvas(master, width=width, height=height,
                                 bg=self.bg, relief=TK.SUNKEN, borderwidth=2)
        self.hscroll = TK.Scrollbar(master, command=self._canvas.xview,
                                    orient=TK.HORIZONTAL)
        self.vscroll = TK.Scrollbar(master, command=self._canvas.yview)
        self._canvas.configure(xscrollcommand=self.hscroll.set,
                               yscrollcommand=self.vscroll.set)
        self.rowconfigure(0, weight=1, minsize=0)
        self.columnconfigure(0, weight=1, minsize=0)
        self._canvas.grid(padx=1, in_ = self, pady=1, row=0,
                column=0, rowspan=1, columnspan=1, sticky='news')
        self.vscroll.grid(padx=1, in_ = self, pady=1, row=0,
                column=1, rowspan=1, columnspan=1, sticky='news')
        self.hscroll.grid(padx=1, in_ = self, pady=1, row=1,
                column=0, rowspan=1, columnspan=1, sticky='news')
        self.reset()
        self._rootwindow.bind('<Configure>', self.onResize) 
Example #9
Source File: pykms_GuiBase.py    From py-kms with The Unlicense 6 votes vote down vote up
def gui_pages_create(self, parent, side, create = {}):
                self.pagewidgets.update({side : {"PageWin" : create,
                                                 "BtnWin"  : None,
                                                 "BtnAni"  :  {"Left"  : None,
                                                               "Right" : None},
                                                 "AniWin"  :  {"Left"  : None,
                                                               "Right" : None},
                                                 "LblAni"  :  {"Left"  : None,
                                                               "Right" : None},
                                                 }
                                         })

                for pagename in self.pagewidgets[side]["PageWin"].keys():
                        page = tk.Canvas(parent, background = self.customcolors['white'], borderwidth = 3, relief = 'ridge')
                        self.pagewidgets[side]["PageWin"][pagename] = page
                        page.grid(row = 0, column = 2, padx = 2, pady = 2, sticky = "nsew")
                        page.grid_columnconfigure(1, weight = 1)
                self.gui_pages_buttons(parent = parent, side = side)
                self.gui_pages_show("PageStart", side = side) 
Example #10
Source File: chartparser_app.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def _sb_canvas(self, root, expand='y',
                   fill='both', side='bottom'):
        """
        Helper for __init__: construct a canvas with a scrollbar.
        """
        cframe =Tkinter.Frame(root, relief='sunk', border=2)
        cframe.pack(fill=fill, expand=expand, side=side)
        canvas = Tkinter.Canvas(cframe, background='#e0e0e0')

        # Give the canvas a scrollbar.
        sb = Tkinter.Scrollbar(cframe, orient='vertical')
        sb.pack(side='right', fill='y')
        canvas.pack(side='left', fill=fill, expand='yes')

        # Connect the scrollbars to the canvas.
        sb['command']= canvas.yview
        canvas['yscrollcommand'] = sb.set

        return (sb, canvas) 
Example #11
Source File: main.py    From WxConn with MIT License 6 votes vote down vote up
def draw(self):
        self.title_canvas = tk.Canvas(self, bg=self.bgcolor, width=width, height=90, bd=0, highlightthickness=0, relief='ridge')
        self.title_pic = self._resize_ads_qrcode(RES_APP_TITLE, size=(260, 90))
        self.title_canvas.create_image(0, 0, anchor='nw', image=self.title_pic)
        self.title_canvas.pack(padx=35, pady=15)

        self.qrcode = tk.Canvas(self, bg=self.bgcolor, width=200, height=200)
        #self.qrcode_pic = self._resize_ads_qrcode('qrcode.png', size=(200, 200))
        #self.qrcode.create_image(0, 0, anchor='nw', image=self.qrcode_pic)
        self.qrcode.pack(pady=30)


        # 提示
        self.lable_tip = tk.Label(self,
                     text='请稍等',  # 标签的文字
                     bg=self.bgcolor,  # 背景颜色
                     font=('楷体',12),  # 字体和字体大小
                     width=15, height=2  # 标签长宽
                     )
        self.lable_tip.pack(pady=2,fill=tk.BOTH)  # 固定窗口位置 
Example #12
Source File: simulator.py    From LED-bot with MIT License 6 votes vote down vote up
def get_canvas():
    """ Creates a Tkinter canvas. """

    from Tkinter import Tk, Canvas, BOTH

    root = Tk()
    root.title('LED bot simulator')
    root.geometry("%sx%s" % (screen_width, screen_height))

    canvas = Canvas(root)
    canvas.pack(fill=BOTH, expand=1)
    canvas.create_rectangle(
        0, 0, screen_width, screen_height, outline="#000", fill="#000"
    )

    return canvas 
Example #13
Source File: graph_canvas.py    From networkx_viewer with GNU General Public License v3.0 6 votes vote down vote up
def _plot_graph(self, graph):
        # Create nodes
        scale = min(self.winfo_width(), self.winfo_height())
        if scale == 1:
            # Canvas not initilized yet; use height and width hints
            scale = int(min(self['width'], self['height']))

        scale -= 50
        if len(graph) > 1:
            layout = self.create_layout(graph, scale=scale, min_distance=50)

            # Find min distance between any node and make sure that is at least
            #  as big as
            for n in graph.nodes():
                self._draw_node(layout[n]+20, n)
        else:
            self._draw_node((scale/2, scale/2), graph.nodes()[0])

        # Create edges
        for frm, to in set(graph.edges()):
            self._draw_edge(frm, to)

        self._graph_changed() 
Example #14
Source File: tokens.py    From networkx_viewer with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, host_canvas, data, node_name):
        tk.Canvas.__init__(self, width=20, height=20, highlightthickness=0)

        self._host_canvas = host_canvas
        self._complete = True
        self._marked = False
        self._default_bg = None

        self.bind('<ButtonPress-1>', self._host_event('onNodeButtonPress'))
        self.bind('<ButtonRelease-1>', self._host_event('onNodeButtonRelease'))
        self.bind('<B1-Motion>', self._host_event('onNodeMotion'))

        self.bind('<Button-3>', self._host_event('onTokenRightClick'))

        self.bind('<Key>', self._host_event('onNodeKey'))
        self.bind('<Enter>', lambda e: self.focus_set())
        self.bind('<Leave>', lambda e: self.master.focus())

        # Draw myself
        self.render(data, node_name) 
Example #15
Source File: turtle.py    From oss-ftp with MIT License 6 votes vote down vote up
def __forwardmethods(fromClass, toClass, toPart, exclude = ()):
    """Helper functions for Scrolled Canvas, used to forward
    ScrolledCanvas-methods to Tkinter.Canvas class.
    """
    _dict = {}
    __methodDict(toClass, _dict)
    for ex in _dict.keys():
        if ex[:1] == '_' or ex[-1:] == '_':
            del _dict[ex]
    for ex in exclude:
        if ex in _dict:
            del _dict[ex]
    for ex in __methods(fromClass):
        if ex in _dict:
            del _dict[ex]

    for method, func in _dict.items():
        d = {'method': method, 'func': func}
        if type(toPart) == types.StringType:
            execString = \
                __stringBody % {'method' : method, 'attribute' : toPart}
        exec execString in d
        fromClass.__dict__[method] = d[method] 
Example #16
Source File: ListPanel.py    From Python-Media-Player with Apache License 2.0 5 votes vote down vote up
def create_song_list_panel(self):
        # Creating Picture Canvas as Background
        background=Tkinter.PhotoImage(file="../Icons/background.gif")
        mainframe=Tkinter.Canvas(self.root)
        mainframe.pack(side='top', expand='yes', fill='both')
        mainframe.image=background
        mainframe.create_image(0, 0, anchor="nw", image=background)
        
        frame0=Tkinter.Frame(mainframe)
        frame0.pack(side='top')
        Tkinter.Label(frame0, text='Search : ', bg='skyblue').pack(side='left', expand='yes', fill='x')
        Tkinter.Entry(frame0, textvariable=self.var1).pack(side='left', expand='yes', fill='x')
        frame0.bind_all('<Any-KeyPress>',self.search_song_trigger)
        frame=Tkinter.Frame(mainframe, bg='skyblue')
        frame.pack(side='top')
        self.list_box=Tkinter.Listbox(frame, bg='powderblue', font=list_box_song_list_font, width=list_box_width, height=list_box_height)
        scrollbar=Tkinter.Scrollbar(frame, bg='skyblue')
        scrollbar.pack(side='right',expand='yes',fill='y')
        scrollbar.config(command=self.list_box.yview)
        self.list_box.config(yscrollcommand=scrollbar.set)
        self.list_box.pack(expand='yes',fill='both',side='right')
        frame1=Tkinter.Frame(mainframe, bg='blue')
        frame1.pack(side='top', expand='yes',fill='x')
        add_fileicon=Tkinter.PhotoImage(file="../Icons/add_file.gif")
        add_directoryicon=Tkinter.PhotoImage(file="../Icons/add_directory.gif")
        list_file=[
        (add_fileicon,'self.ask_for_play_song_direct'),
        (add_directoryicon,'self.ask_for_directory'),
        ]
        for i,j in list_file:
                storeobj=Tkinter.Button(frame1, image=i, command=eval(j), bg='blue')
                storeobj.pack(side='left')
                storeobj.image=i
        self.list_box.bind('<Double-Button-1>',self.play_on_click)
        return self.update_list_box_songs() 
Example #17
Source File: sshmonitor-tk.py    From SSHMonitor2.7 with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):

        self.tk = tkinter.Tk()

        self.tk.geometry("%dx%d+%d+%d" % (330, 80, 200, 150))
        self.tk.title("SSHMonitor")


        canvas = tkinter.Canvas(self.tk, bg="white", width=500, height=300)
        canvas.pack(side="top", fill="both", expand=True)
        cid = canvas.create_text(10, 10, anchor="nw")

        canvas.itemconfig(cid, text="New SSH activity!") 
Example #18
Source File: tkgui.py    From ATX with Apache License 2.0 5 votes vote down vote up
def _init_items(self):
        root = self._root
        frm_control = tk.Frame(root, bg='blue')
        frm_control.grid(column=0, row=0)
        frm_screen = tk.Frame(root, bg='#aaa')
        frm_screen.grid(column=0, row=1)

        tk.Button(frm_control, text="Refresh", command=self._redraw).grid(column=0, row=0, sticky=tk.W)
        tk.Button(frm_control, text="Save crop", command=self._save_crop).grid(column=1, row=0, sticky=tk.W)

        self.canvas = tk.Canvas(frm_screen, bg="blue", bd=0, highlightthickness=0, relief='ridge')
        self.canvas.grid(column=0, row=0, padx=10, pady=10)
        self.canvas.bind("<Button-1>", self._stroke_start)
        self.canvas.bind("<B1-Motion>", self._stroke_move)
        self.canvas.bind("<B1-ButtonRelease>", self._stroke_done) 
Example #19
Source File: slam.py    From slam with Apache License 2.0 5 votes vote down vote up
def initializeCanvas():
    global can,win	
    win = Tk()
    win.title('SLAM')
    can = Canvas(win, width=gridSize/cellSize,height=gridSize/cellSize)
    can.pack() 
    #start the showMap method is a new thread
    thread.start_new_thread(showMap,(None,))
    win.mainloop()

#this function will be called in a new thread, so that it continuously draws the changing map on the canvas 
Example #20
Source File: turtle.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __repr__(self):
        return "(%.2f,%.2f)" % self


##############################################################################
### From here up to line    : Tkinter - Interface for turtle.py            ###
### May be replaced by an interface to some different graphics toolkit     ###
##############################################################################

## helper functions for Scrolled Canvas, to forward Canvas-methods
## to ScrolledCanvas class 
Example #21
Source File: recipe-52275.py    From code with MIT License 5 votes vote down vote up
def plot(self, width_in=400, height_in=400):

		import colormap
		import Tkinter

		cmax = max(self.values())
		cmin = min(self.values())
		
		offset =  0.05*min(width_in, height_in)
		xmin, ymin, xmax, ymax = 0,0,self.size()[0], self.size()[1]
		scale =  min(0.9*width_in, 0.9*height_in)/max(xmax-xmin, ymax-ymin)

		root = Tkinter.Tk()
		frame = Tkinter.Frame(root)
		frame.pack()
		
		text = Tkinter.Label(width=20, height=10, text='matrix sparsity')
		text.pack()
		

		canvas = Tkinter.Canvas(bg="black", width=width_in, height=height_in)
		canvas.pack()

		button = Tkinter.Button(frame, text="OK?", fg="red", command=frame.quit)
		button.pack()

		for index in self.keys():
			ix, iy = index[0], ymax-index[1]-1
			ya, xa = offset+scale*(ix  ), height_in -offset-scale*(iy  )
			yb, xb = offset+scale*(ix+1), height_in -offset-scale*(iy  )
			yc, xc = offset+scale*(ix+1), height_in -offset-scale*(iy+1)
			yd, xd = offset+scale*(ix  ), height_in -offset-scale*(iy+1)
			color = colormap.strRgb(self[index], cmin, cmax)
			canvas.create_polygon(xa, ya, xb, yb, xc, yc, xd, yd, fill=color)
		
		root.mainloop() 
Example #22
Source File: pykms_GuiBase.py    From py-kms with The Unlicense 5 votes vote down vote up
def gui_pages_buttons(self, parent, side):
                btnwin = tk.Canvas(parent, background = self.customcolors['white'], borderwidth = 3, relief = 'ridge')
                btnwin.grid(row = 14, column = 2, padx = 2, pady = 2, sticky = 'nsew')
                btnwin.grid_columnconfigure(1, weight = 1)
                self.pagewidgets[side]["BtnWin"] = btnwin

                for position in ["Left", "Right"]:
                        if position == "Left":
                                col = [0, 0, 1]
                                stick = 'e'
                        elif position == "Right":
                                col = [2, 1, 0]
                                stick = 'w'

                        aniwin = tk.Canvas(btnwin, background = self.customcolors['white'], borderwidth = 0, relief = 'ridge')
                        aniwin.grid(row = 0, column = col[0], padx = 5, pady = 5, sticky = 'nsew')
                        self.pagewidgets[side]["AniWin"][position] = aniwin

                        lblani = tk.Label(aniwin, width = 1, height = 1)
                        lblani.grid(row = 0, column = col[1], padx = 2, pady = 2, sticky = stick)
                        self.pagewidgets[side]["LblAni"][position] = lblani

                        btnani = tk.Button(aniwin)
                        btnani.grid(row = 0, column = col[2], padx = 2, pady = 2, sticky = stick)
                        self.pagewidgets[side]["BtnAni"][position] = btnani
                ## Customize buttons.
                custom_pages(self, side) 
Example #23
Source File: tkvt100.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, *args, **kw):
        global ttyFont, fontHeight, fontWidth
        ttyFont = tkFont.Font(family = 'Courier', size = 10)
        fontWidth = max(map(ttyFont.measure, string.ascii_letters+string.digits))
        fontHeight = int(ttyFont.metrics()['linespace'])
        self.width = kw.get('width', 80)
        self.height = kw.get('height', 25)
        self.callback = kw['callback']
        del kw['callback']
        kw['width'] = w = fontWidth * self.width
        kw['height'] = h = fontHeight * self.height
        Tkinter.Frame.__init__(self, *args, **kw)
        self.canvas = Tkinter.Canvas(bg='#000000', width=w, height=h)
        self.canvas.pack(side=Tkinter.TOP, fill=Tkinter.BOTH, expand=1)
        self.canvas.bind('<Key>', self.keyPressed)
        self.canvas.bind('<1>', lambda x: 'break')
        self.canvas.bind('<Up>', self.upPressed)
        self.canvas.bind('<Down>', self.downPressed)
        self.canvas.bind('<Left>', self.leftPressed)
        self.canvas.bind('<Right>', self.rightPressed)
        self.canvas.focus()

        self.ansiParser = ansi.AnsiParser(ansi.ColorText.WHITE, ansi.ColorText.BLACK)
        self.ansiParser.writeString = self.writeString
        self.ansiParser.parseCursor = self.parseCursor
        self.ansiParser.parseErase = self.parseErase
        #for (a, b) in colorMap.items():
        #    self.canvas.tag_config(a, foreground=b)
        #    self.canvas.tag_config('b'+a, background=b)
        #self.canvas.tag_config('underline', underline=1)

        self.x = 0 
        self.y = 0
        self.cursor = self.canvas.create_rectangle(0,0,fontWidth-1,fontHeight-1,fill='green',outline='green') 
Example #24
Source File: tkagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def test(aggimage):
    import time
    r = Tk.Tk()
    c = Tk.Canvas(r, width=aggimage.width, height=aggimage.height)
    c.pack()
    p = Tk.PhotoImage(width=aggimage.width, height=aggimage.height)
    blit(p, aggimage)
    c.create_image(aggimage.width,aggimage.height,image=p)
    blit(p, aggimage)
    while 1: r.update_idletasks() 
Example #25
Source File: test_widgets.py    From oss-ftp with MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return tkinter.Canvas(self.root, **kwargs) 
Example #26
Source File: Tkdnd.py    From oss-ftp with MIT License 5 votes vote down vote up
def __init__(self, root):
        self.top = Tkinter.Toplevel(root)
        self.canvas = Tkinter.Canvas(self.top, width=100, height=100)
        self.canvas.pack(fill="both", expand=1)
        self.canvas.dnd_accept = self.dnd_accept 
Example #27
Source File: turtle.py    From oss-ftp with MIT License 5 votes vote down vote up
def __init__(self, canvas=None,
                 shape=_CFG["shape"],
                 undobuffersize=_CFG["undobuffersize"],
                 visible=_CFG["visible"]):
        if isinstance(canvas, _Screen):
            self.screen = canvas
        elif isinstance(canvas, TurtleScreen):
            if canvas not in RawTurtle.screens:
                RawTurtle.screens.append(canvas)
            self.screen = canvas
        elif isinstance(canvas, (ScrolledCanvas, Canvas)):
            for screen in RawTurtle.screens:
                if screen.cv == canvas:
                    self.screen = screen
                    break
            else:
                self.screen = TurtleScreen(canvas)
                RawTurtle.screens.append(self.screen)
        else:
            raise TurtleGraphicsError("bad canvas argument %s" % canvas)

        screen = self.screen
        TNavigator.__init__(self, screen.mode())
        TPen.__init__(self)
        screen._turtles.append(self)
        self.drawingLineItem = screen._createline()
        self.turtle = _TurtleImage(screen, shape)
        self._poly = None
        self._creatingPoly = False
        self._fillitem = self._fillpath = None
        self._shown = visible
        self._hidden_from_screen = False
        self.currentLineItem = screen._createline()
        self.currentLine = [self._position]
        self.items = [self.currentLineItem]
        self.stampItems = []
        self._undobuffersize = undobuffersize
        self.undobuffer = Tbuffer(undobuffersize)
        self._update() 
Example #28
Source File: turtle.py    From oss-ftp with MIT License 5 votes vote down vote up
def getcanvas(self):
        """Return the Canvas of this TurtleScreen.

        No argument.

        Example (for a Screen instance named screen):
        >>> cv = screen.getcanvas()
        >>> cv
        <turtle.ScrolledCanvas instance at 0x010742D8>
        """
        return self.cv 
Example #29
Source File: turtle.py    From oss-ftp with MIT License 5 votes vote down vote up
def _onkey(self, fun, key):
        """Bind fun to key-release event of key.
        Canvas must have focus. See method listen
        """
        if fun is None:
            self.cv.unbind("<KeyRelease-%s>" % key, None)
        else:
            def eventfun(event):
                fun()
            self.cv.bind("<KeyRelease-%s>" % key, eventfun) 
Example #30
Source File: turtle.py    From oss-ftp with MIT License 5 votes vote down vote up
def __init__(self, master, width=500, height=350,
                                          canvwidth=600, canvheight=500):
        TK.Frame.__init__(self, master, width=width, height=height)
        self._rootwindow = self.winfo_toplevel()
        self.width, self.height = width, height
        self.canvwidth, self.canvheight = canvwidth, canvheight
        self.bg = "white"
        self._canvas = TK.Canvas(master, width=width, height=height,
                                 bg=self.bg, relief=TK.SUNKEN, borderwidth=2)
        self.hscroll = TK.Scrollbar(master, command=self._canvas.xview,
                                    orient=TK.HORIZONTAL)
        self.vscroll = TK.Scrollbar(master, command=self._canvas.yview)
        self._canvas.configure(xscrollcommand=self.hscroll.set,
                               yscrollcommand=self.vscroll.set)
        self.rowconfigure(0, weight=1, minsize=0)
        self.columnconfigure(0, weight=1, minsize=0)
        self._canvas.grid(padx=1, in_ = self, pady=1, row=0,
                column=0, rowspan=1, columnspan=1, sticky='news')
        self.vscroll.grid(padx=1, in_ = self, pady=1, row=0,
                column=1, rowspan=1, columnspan=1, sticky='news')
        self.hscroll.grid(padx=1, in_ = self, pady=1, row=1,
                column=0, rowspan=1, columnspan=1, sticky='news')
        self.reset()
        self._rootwindow.bind('<Configure>', self.onResize)