Python Tkinter.Frame() Examples

The following are 30 code examples of Tkinter.Frame(). 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: annotation_gui.py    From SEM with MIT License 9 votes vote down vote up
def preferences(self, event=None):
        preferenceTop = tkinter.Toplevel()
        preferenceTop.focus_set()
        
        notebook = ttk.Notebook(preferenceTop)
        
        frame1 = ttk.Frame(notebook)
        notebook.add(frame1, text='general')
        frame2 = ttk.Frame(notebook)
        notebook.add(frame2, text='shortcuts')

        c = ttk.Checkbutton(frame1, text="Match whole word when broadcasting annotation", variable=self._whole_word)
        c.pack()
        
        shortcuts_vars = []
        shortcuts_gui = []
        cur_row = 0
        j = -1
        frame_list = []
        frame_list.append(ttk.LabelFrame(frame2, text="common shortcuts"))
        frame_list[-1].pack(fill="both", expand="yes")
        for i, shortcut in enumerate(self.shortcuts):
            j += 1
            key, cmd, bindings = shortcut
            name, command = cmd
            shortcuts_vars.append(tkinter.StringVar(frame_list[-1], value=key))
            tkinter.Label(frame_list[-1], text=name).grid(row=cur_row, column=0, sticky=tkinter.W)
            entry = tkinter.Entry(frame_list[-1], textvariable=shortcuts_vars[j])
            entry.grid(row=cur_row, column=1)
            cur_row += 1
        notebook.pack()
    
    #
    # ? menu methods
    # 
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: pipark_setup_args.py    From PiPark with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, master = None):
        """Application constructor method. """

        # run super constructor method
        tk.Frame.__init__(self, master)
        
        # set alignment inside the frame
        self.grid(padx = 10, pady = 10)
        
        # create widgets
        self.__createMenu()  # menu canvas: holds the buttons and menu bar image
    

    # --------------------------------------------------------------------------
    #   Create Options Menu
    # -------------------------------------------------------------------------- 
Example #4
Source File: SikuliGui.py    From lackey with MIT License 6 votes vote down vote up
def __init__(self, master, textvariable=None, *args, **kwargs):

        tk.Frame.__init__(self, master)
        # Init GUI

        self._y_scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)

        self._text_widget = tk.Text(self, yscrollcommand=self._y_scrollbar.set, *args, **kwargs)
        self._text_widget.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)

        self._y_scrollbar.config(command=self._text_widget.yview)
        self._y_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)

        if textvariable is not None:
            if not isinstance(textvariable, tk.Variable):
                raise TypeError("tkinter.Variable type expected, {} given.".format(
                    type(textvariable)))
            self._text_variable = textvariable
            self.var_modified()
            self._text_trace = self._text_widget.bind('<<Modified>>', self.text_modified)
            self._var_trace = textvariable.trace("w", self.var_modified) 
Example #5
Source File: test_geometry_managers.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_grid_propagate(self):
        self.assertEqual(self.root.grid_propagate(), True)
        with self.assertRaises(TypeError):
            self.root.grid_propagate(False, False)
        self.root.grid_propagate(False)
        self.assertFalse(self.root.grid_propagate())
        f = tkinter.Frame(self.root, width=100, height=100, bg='red')
        f.grid_configure(row=0, column=0)
        self.root.update()
        self.assertEqual(f.winfo_width(), 100)
        self.assertEqual(f.winfo_height(), 100)
        f.grid_propagate(False)
        g = tkinter.Frame(self.root, width=75, height=85, bg='green')
        g.grid_configure(in_=f, row=0, column=0)
        self.root.update()
        self.assertEqual(f.winfo_width(), 100)
        self.assertEqual(f.winfo_height(), 100)
        f.grid_propagate(True)
        self.root.update()
        self.assertEqual(f.winfo_width(), 75)
        self.assertEqual(f.winfo_height(), 85) 
Example #6
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 #7
Source File: ScrolledText.py    From BinderFilter with MIT License 6 votes vote down vote up
def __init__(self, master=None, **kw):
        self.frame = Frame(master)
        self.vbar = Scrollbar(self.frame)
        self.vbar.pack(side=RIGHT, fill=Y)

        kw.update({'yscrollcommand': self.vbar.set})
        Text.__init__(self, self.frame, **kw)
        self.pack(side=LEFT, fill=BOTH, expand=True)
        self.vbar['command'] = self.yview

        # Copy geometry methods of self.frame without overriding Text
        # methods -- hack!
        text_meths = vars(Text).keys()
        methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys()
        methods = set(methods).difference(text_meths)

        for m in methods:
            if m[0] != '_' and m != 'config' and m != 'configure':
                setattr(self, m, getattr(self.frame, m)) 
Example #8
Source File: ScrolledText.py    From oss-ftp with MIT License 6 votes vote down vote up
def __init__(self, master=None, **kw):
        self.frame = Frame(master)
        self.vbar = Scrollbar(self.frame)
        self.vbar.pack(side=RIGHT, fill=Y)

        kw.update({'yscrollcommand': self.vbar.set})
        Text.__init__(self, self.frame, **kw)
        self.pack(side=LEFT, fill=BOTH, expand=True)
        self.vbar['command'] = self.yview

        # Copy geometry methods of self.frame without overriding Text
        # methods -- hack!
        text_meths = vars(Text).keys()
        methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys()
        methods = set(methods).difference(text_meths)

        for m in methods:
            if m[0] != '_' and m != 'config' and m != 'configure':
                setattr(self, m, getattr(self.frame, m)) 
Example #9
Source File: backend_tkagg.py    From Computable with MIT License 6 votes vote down vote up
def _init_toolbar(self):
        xmin, xmax = self.canvas.figure.bbox.intervalx
        height, width = 50, xmax-xmin
        Tk.Frame.__init__(self, master=self.window,
                          width=int(width), height=int(height),
                          borderwidth=2)

        self.update()  # Make axes menu

        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                # spacer, unhandled in Tk
                pass
            else:
                button = self._Button(text=text, file=image_file,
                                   command=getattr(self, callback))
                if tooltip_text is not None:
                    ToolTip.createToolTip(button, tooltip_text)

        self.message = Tk.StringVar(master=self)
        self._message_label = Tk.Label(master=self, textvariable=self.message)
        self._message_label.pack(side=Tk.RIGHT)
        self.pack(side=Tk.BOTTOM, fill=Tk.X) 
Example #10
Source File: pykms_GuiMisc.py    From py-kms with The Unlicense 6 votes vote down vote up
def __init__(self, master, radios, font, changed, **kwargs):
                tk.Frame.__init__(self, master)

                self.master = master
                self.radios = radios
                self.font = font
                self.changed = changed

                self.scrollv = tk.Scrollbar(self, orient = "vertical")
                self.textbox = tk.Text(self, yscrollcommand = self.scrollv.set, **kwargs)
                self.scrollv.config(command = self.textbox.yview)
                # layout.
                self.scrollv.pack(side = "right", fill = "y")
                self.textbox.pack(side = "left", fill = "both", expand = True)
                # create radiobuttons.
                self.radiovar = tk.StringVar()
                self.radiovar.set('FILE')
                self.create() 
Example #11
Source File: backend_tkagg.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def _init_toolbar(self):
        xmin, xmax = self.canvas.figure.bbox.intervalx
        height, width = 50, xmax-xmin
        Tk.Frame.__init__(self, master=self.window,
                          width=int(width), height=int(height),
                          borderwidth=2)

        self.update()  # Make axes menu

        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                # spacer, unhandled in Tk
                pass
            else:
                button = self._Button(text=text, file=image_file,
                                   command=getattr(self, callback))
                if tooltip_text is not None:
                    ToolTip.createToolTip(button, tooltip_text)

        self.message = Tk.StringVar(master=self)
        self._message_label = Tk.Label(master=self, textvariable=self.message)
        self._message_label.pack(side=Tk.RIGHT)
        self.pack(side=Tk.BOTTOM, fill=Tk.X) 
Example #12
Source File: kimmo.py    From razzy-spinner with GNU General Public License v3.0 6 votes vote down vote up
def buttonbox(self):
        # add standard button box. override if you don't want the
        # standard buttons

        box = Tkinter.Frame(self)

        w = Tkinter.Button(box, text="OK", width=10, command=self.ok, default="active")
        w.pack(side="left", padx=5, pady=5)
        w = Tkinter.Button(box, text="Cancel", width=10, command=self.cancel)
        w.pack(side="left", padx=5, pady=5)

        self.bind("&lt;Return&gt;", self.ok)
        self.bind("&lt;Escape&gt;", self.cancel)

        box.pack()

    #
    # standard button semantics 
Example #13
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_place_slaves(self):
        foo = tkinter.Frame(self.root)
        bar = tkinter.Frame(self.root)
        self.assertEqual(foo.place_slaves(), [])
        bar.place_configure(in_=foo)
        self.assertEqual(foo.place_slaves(), [bar])
        with self.assertRaises(TypeError):
            foo.place_slaves(0) 
Example #14
Source File: test_searchdialogbase.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_make_frame(self):
        self.dialog.row = 0
        self.dialog.top = Toplevel(self.root)
        frame, label = self.dialog.make_frame()
        self.assertEqual(label, '')
        self.assertIsInstance(frame, Frame)

        frame, label = self.dialog.make_frame('testlabel')
        self.assertEqual(label['text'], 'testlabel')
        self.assertIsInstance(frame, Frame) 
Example #15
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_grid_location(self):
        with self.assertRaises(TypeError):
            self.root.grid_location()
        with self.assertRaises(TypeError):
            self.root.grid_location(0)
        with self.assertRaises(TypeError):
            self.root.grid_location(0, 0, 0)
        with self.assertRaisesRegexp(TclError, 'bad screen distance "x"'):
            self.root.grid_location('x', 'y')
        with self.assertRaisesRegexp(TclError, 'bad screen distance "y"'):
            self.root.grid_location('1c', 'y')
        t = self.root
        # de-maximize
        t.wm_geometry('1x1+0+0')
        t.wm_geometry('')
        f = tkinter.Frame(t, width=200, height=100,
                          highlightthickness=0, bg='red')
        self.assertEqual(f.grid_location(10, 10), (-1, -1))
        f.grid_configure()
        self.root.update()
        self.assertEqual(t.grid_location(-10, -10), (-1, -1))
        self.assertEqual(t.grid_location(-10, 0), (-1, 0))
        self.assertEqual(t.grid_location(-1, 0), (-1, 0))
        self.assertEqual(t.grid_location(0, -10), (0, -1))
        self.assertEqual(t.grid_location(0, -1), (0, -1))
        self.assertEqual(t.grid_location(0, 0), (0, 0))
        self.assertEqual(t.grid_location(200, 0), (0, 0))
        self.assertEqual(t.grid_location(201, 0), (1, 0))
        self.assertEqual(t.grid_location(0, 100), (0, 0))
        self.assertEqual(t.grid_location(0, 101), (0, 1))
        self.assertEqual(t.grid_location(201, 101), (1, 1)) 
Example #16
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_grid_bbox(self):
        self.assertEqual(self.root.grid_bbox(), (0, 0, 0, 0))
        self.assertEqual(self.root.grid_bbox(0, 0), (0, 0, 0, 0))
        self.assertEqual(self.root.grid_bbox(0, 0, 1, 1), (0, 0, 0, 0))
        with self.assertRaisesRegexp(TclError, 'expected integer but got "x"'):
            self.root.grid_bbox('x', 0)
        with self.assertRaisesRegexp(TclError, 'expected integer but got "x"'):
            self.root.grid_bbox(0, 'x')
        with self.assertRaisesRegexp(TclError, 'expected integer but got "x"'):
            self.root.grid_bbox(0, 0, 'x', 0)
        with self.assertRaisesRegexp(TclError, 'expected integer but got "x"'):
            self.root.grid_bbox(0, 0, 0, 'x')
        with self.assertRaises(TypeError):
            self.root.grid_bbox(0, 0, 0, 0, 0)
        t = self.root
        # de-maximize
        t.wm_geometry('1x1+0+0')
        t.wm_geometry('')
        f1 = tkinter.Frame(t, width=75, height=75, bg='red')
        f2 = tkinter.Frame(t, width=90, height=90, bg='blue')
        f1.grid_configure(row=0, column=0)
        f2.grid_configure(row=1, column=1)
        self.root.update()
        self.assertEqual(t.grid_bbox(), (0, 0, 165, 165))
        self.assertEqual(t.grid_bbox(0, 0), (0, 0, 75, 75))
        self.assertEqual(t.grid_bbox(0, 0, 1, 1), (0, 0, 165, 165))
        self.assertEqual(t.grid_bbox(1, 1), (75, 75, 90, 90))
        self.assertEqual(t.grid_bbox(10, 10, 0, 0), (0, 0, 165, 165))
        self.assertEqual(t.grid_bbox(-2, -2, -1, -1), (0, 0, 0, 0))
        self.assertEqual(t.grid_bbox(10, 10, 12, 12), (165, 165, 0, 0)) 
Example #17
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_grid_configure_in(self):
        f = tkinter.Frame(self.root)
        b = tkinter.Button(self.root)
        self.assertEqual(b.grid_info(), {})
        b.grid_configure()
        self.assertEqual(b.grid_info()['in'], self.root)
        b.grid_configure(in_=f)
        self.assertEqual(b.grid_info()['in'], f)
        b.grid_configure({'in': self.root})
        self.assertEqual(b.grid_info()['in'], self.root) 
Example #18
Source File: backend_tkagg.py    From Computable with MIT License 5 votes vote down vote up
def destroy(self, *args):
        del self.message
        Tk.Frame.destroy(self, *args) 
Example #19
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def create2(self):
        pack = tkinter.Toplevel(self.root, name='pack')
        pack.wm_geometry('300x200+0+0')
        pack.wm_minsize(1, 1)
        a = tkinter.Frame(pack, name='a', width=20, height=40, bg='red')
        b = tkinter.Frame(pack, name='b', width=50, height=30, bg='blue')
        c = tkinter.Frame(pack, name='c', width=80, height=80, bg='green')
        d = tkinter.Frame(pack, name='d', width=40, height=30, bg='yellow')
        return pack, a, b, c, d 
Example #20
Source File: backend_tkagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def __init__(self, canvas, window):
        self.canvas = canvas
        self.window = window
        self._idle = True
        #Tk.Frame.__init__(self, master=self.canvas._tkcanvas)
        NavigationToolbar2.__init__(self, canvas) 
Example #21
Source File: test_widgets.py    From oss-ftp with MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return tkinter.Frame(self.root, **kwargs) 
Example #22
Source File: test_searchdialogbase.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_make_button(self):
        self.dialog.top = Toplevel(self.root)
        self.dialog.buttonframe = Frame(self.dialog.top)
        btn = self.dialog.make_button('Test', self.dialog.close)
        self.assertEqual(btn['text'], 'Test') 
Example #23
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_place_forget(self):
        foo = tkinter.Frame(self.root)
        foo.place_configure(width=50, height=50)
        self.root.update()
        foo.place_forget()
        self.root.update()
        self.assertFalse(foo.winfo_ismapped())
        with self.assertRaises(TypeError):
            foo.place_forget(0) 
Example #24
Source File: backend_tkagg.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def destroy(self, *args):
        del self.message
        Tk.Frame.destroy(self, *args) 
Example #25
Source File: main.py    From WxConn with MIT License 5 votes vote down vote up
def __init__(self, master=None, *args, **kwargs):
        tk.Frame.__init__(self, master=master, *args, **kwargs)
        self.canvas=None
        self.header_path = 'header.jpg'
        self.bgcolor='white'
        self.success = None
        # 推广公众号的二维码路径
        self.set_ads_qr_path = os.listdir(PUBLIC_QR)
        # 当前ads的下标
        self.ads_index = 0 
Example #26
Source File: backend_tkagg.py    From Computable with MIT License 5 votes vote down vote up
def __init__(self, canvas, window):
        self.canvas = canvas
        self.window = window
        self._idle = True
        #Tk.Frame.__init__(self, master=self.canvas._tkcanvas)
        NavigationToolbar2.__init__(self, canvas) 
Example #27
Source File: main.py    From PiPark with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, master = None):
        """Application constructor method. """
        if self.__is_verbose: print "INFO: Application constructor called."

        # run super constructor method
        tk.Frame.__init__(self, master)
        
        # apply grid layout
        self.grid()
        
        # give application a reference to the global camera object
        global camera
        self.__camera = camera
        self.__camera.awb_mode = 'auto'
        self.__camera.exposure_mode = 'auto'
        
        # populate the application WITH W-W-W-WWIDDDDGEETTSS
        self.__createWidgets()
        
        # create canvas to display logo
        self.logo = tk.Canvas(self, width = 400, height = 148)
        self.logo.grid(row = 0, column = 0, rowspan = 1, columnspan = 2)
        self.loadImage("./images/logo_main.jpeg", self.logo, 400/2, 148/2)
        self.updateText()
        
        # create key-press handlers -> set focus to this frame
        self.bind("<Escape>", self.escapePressHandler)
        self.focus_set() 
Example #28
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 #29
Source File: interactive_gui.py    From PcapXray with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, master):
        self.closing = False
        self.browser = None
        # Python2 has a ttk frame error of using self as argument so use tk 
        #ttk.Frame.__init__(self, master, width=500, height=400, padding="10 10 10 10", relief=GROOVE)
        tk.Frame.__init__(self, master, width=500, height=400)
        self.bind("<FocusIn>", self.on_focus_in)
        self.bind("<FocusOut>", self.on_focus_out)
        self.bind("<Configure>", self.on_configure)
        self.focus_set() 
Example #30
Source File: MainWindow.py    From Diabetic-Retinopathy-Feature-Extraction-using-Fundus-Images with GNU General Public License v3.0 5 votes vote down vote up
def browseWindow(self):
        FILEOPENOPTIONS = dict(defaultextension='*.*', filetypes=[('jpeg','*.jpeg'), ('jpg','*.jpg'), ('All Files','*.*')])
        self.fileName = tkFileDialog.askopenfilename(**FILEOPENOPTIONS)
        image = Image.open(self.fileName)           ##Opening Image
        #imgRes = image.resize((299,299))            ##Resizing Image
        self.listOfWinFrame[0].setImage(image)     ##Passing Image to Frame for setting
        self.listOfWinFrame[0].displayImage()       ##Displaying Image
        self.ExEd.setImage(image)                  ##Passing Image to Exudates for Processing
        self.BV.setImage(image)