Python Tkinter.Button() Examples

The following are 30 code examples of Tkinter.Button(). 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: viewer.py    From networkx_viewer with GNU General Public License v3.0 7 votes vote down vote up
def __init__(self, main_window, msg='Please enter a node:'):
        tk.Toplevel.__init__(self)
        self.main_window = main_window
        self.title('Node Entry')
        self.geometry('170x160')
        self.rowconfigure(3, weight=1)

        tk.Label(self, text=msg).grid(row=0, column=0, columnspan=2,
                                      sticky='NESW',padx=5,pady=5)
        self.posibilities = [d['dataG_id'] for n,d in
                    main_window.canvas.dispG.nodes_iter(data=True)]
        self.entry = AutocompleteEntry(self.posibilities, self)
        self.entry.bind('<Return>', lambda e: self.destroy(), add='+')
        self.entry.grid(row=1, column=0, columnspan=2, sticky='NESW',padx=5,pady=5)

        tk.Button(self, text='Ok', command=self.destroy).grid(
            row=3, column=0, sticky='ESW',padx=5,pady=5)
        tk.Button(self, text='Cancel', command=self.cancel).grid(
            row=3, column=1, sticky='ESW',padx=5,pady=5)

        # Make modal
        self.winfo_toplevel().wait_window(self) 
Example #2
Source File: Tkinter.py    From oss-ftp with MIT License 6 votes vote down vote up
def _test():
    root = Tk()
    text = "This is Tcl/Tk version %s" % TclVersion
    if TclVersion >= 8.1:
        try:
            text = text + unicode("\nThis should be a cedilla: \347",
                                  "iso-8859-1")
        except NameError:
            pass # no unicode support
    label = Label(root, text=text)
    label.pack()
    test = Button(root, text="Click me!",
              command=lambda root=root: root.test.configure(
                  text="[%s]" % root.test['text']))
    test.pack()
    root.test = test
    quit = Button(root, text="QUIT", command=root.destroy)
    quit.pack()
    # The following three commands are needed so the window pops
    # up on top on Windows...
    root.iconify()
    root.update()
    root.deiconify()
    root.mainloop() 
Example #3
Source File: WindowFrame.py    From Diabetic-Retinopathy-Feature-Extraction-using-Fundus-Images with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, mainObj, MainWin, wWidth, wHeight, function, Object, xAxis = 10, yAxis = 10):
        self.xAxis = xAxis
        self.yAxis = yAxis
        self.MainWindow = MainWin
        self.MainObj = mainObj
        if (self.callingObj != 0):    
            self.callingObj = Object
        
        if (function != 0):
            self.method = function
        
        global winFrame
        self.winFrame = Tkinter.Frame(self.MainWindow, width = wWidth, height = wHeight)
        self.winFrame['borderwidth'] = 5
        self.winFrame['relief'] = 'ridge'
        self.winFrame.place(x=xAxis,y=yAxis)
        #self.winFrame.configure(background="White")


        self.btnQuit= Tkinter.Button(self.winFrame, text = "Close", width=8, command= lambda: self.quitProgram(self.MainWindow))
        self.btnQuit.place(x=650, y=450)
        self.btnNext = Tkinter.Button(self.winFrame, text = "Next", width=8, command= lambda: self.NextWindow(self.method))
        self.btnNext.place(x=575, y=450) 
Example #4
Source File: agents.py    From aima with MIT License 6 votes vote down vote up
def __init__(self, parent, env, canvas):
        super(EnvToolbar, self).__init__(parent, relief='raised', bd=2)

        # Initialize instance variables

        self.env = env
        self.canvas = canvas
        self.running = False
        self.speed = 1.0

        # Create buttons and other controls

        for txt, cmd in [('Step >', self.env.step),
                         ('Run >>', self.run),
                         ('Stop [ ]', self.stop),
                         ('List things', self.list_things),
                         ('List agents', self.list_agents)]:
            tk.Button(self, text=txt, command=cmd).pack(side='left')

        tk.Label(self, text='Speed').pack(side='left')
        scale = tk.Scale(self, orient='h',
                         from_=(1.0), to=10.0, resolution=1.0,
                         command=self.set_speed)
        scale.set(self.speed)
        scale.pack(side='left') 
Example #5
Source File: main.py    From PiPark with GNU General Public License v2.0 6 votes vote down vote up
def __createWidgets(self):
        """Create the widgets. """
        if self.__is_verbose: print "INFO: Creating Widgets!"
        
        # create show preview button
        self.preview_button = tk.Button(self, text = "Show Camera Feed",
            command = self.clickStartPreview)
        self.preview_button.grid(row = 1, column = 0, 
            sticky = tk.W + tk.E + tk.N + tk.S)
        
        # create quit button
        self.quit_button = tk.Button(self, text = "Quit",
            command = self.clickQuit)
        self.quit_button.grid(row = 1, column = 1, 
            sticky = tk.W + tk.E + tk.N + tk.S)
    
    # --------------------------------------------------------------------------
    #   Load Image
    # -------------------------------------------------------------------------- 
Example #6
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 #7
Source File: Emotion Recognition.py    From Emotion-Recognition-Using-SVMs with MIT License 6 votes vote down vote up
def record_result(self, smile=True):
        print "Image", self.index + 1, ":", "Happy" if smile is True else "Sad"
        self.results[str(self.index)] = smile



# ===================================
# Callback function for the buttons
# ===================================
## smileCallback()              : Gets called when "Happy" Button is pressed
## noSmileCallback()            : Gets called when "Sad" Button is pressed
## updateImageCount()           : Displays the number of images processed
## displayFace()                : Gets called internally by either of the button presses
## displayBarGraph(isBarGraph)  : computes the bar graph after classification is completed 100%
## _begin()                     : Resets the Dataset & Starts from the beginning
## _quit()                      : Quits the Application
## printAndSaveResult()         : Save and print the classification result
## loadResult()                 : Loading the previously stored classification result
## run_once(m)                  : Decorator to allow functions to run only once 
Example #8
Source File: dynOptionMenuWidget.py    From oss-ftp with MIT License 6 votes vote down vote up
def _dyn_option_menu(parent):  # htest #
    from Tkinter import Toplevel

    top = Toplevel()
    top.title("Tets dynamic option menu")
    top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
                  parent.winfo_rooty() + 150))
    top.focus_set()

    var = StringVar(top)
    var.set("Old option set") #Set the default value
    dyn = DynOptionMenu(top,var, "old1","old2","old3","old4")
    dyn.pack()

    def update():
        dyn.SetMenu(["new1","new2","new3","new4"], value="new option set")
    button = Button(top, text="Change option set", command=update)
    button.pack() 
Example #9
Source File: test_geometry_managers.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_grid_remove(self):
        b = tkinter.Button(self.root)
        c = tkinter.Button(self.root)
        b.grid_configure(row=2, column=2, rowspan=2, columnspan=2,
                         padx=3, pady=4, sticky='ns')
        self.assertEqual(self.root.grid_slaves(), [b])
        b.grid_remove()
        c.grid_remove()
        self.assertEqual(self.root.grid_slaves(), [])
        self.assertEqual(b.grid_info(), {})
        b.grid_configure(row=0, column=0)
        info = b.grid_info()
        self.assertEqual(info['row'], self._str(0))
        self.assertEqual(info['column'], self._str(0))
        self.assertEqual(info['rowspan'], self._str(2))
        self.assertEqual(info['columnspan'], self._str(2))
        self.assertEqual(info['padx'], self._str(3))
        self.assertEqual(info['pady'], self._str(4))
        self.assertEqual(info['sticky'], 'ns') 
Example #10
Source File: test_geometry_managers.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_grid_forget(self):
        b = tkinter.Button(self.root)
        c = tkinter.Button(self.root)
        b.grid_configure(row=2, column=2, rowspan=2, columnspan=2,
                         padx=3, pady=4, sticky='ns')
        self.assertEqual(self.root.grid_slaves(), [b])
        b.grid_forget()
        c.grid_forget()
        self.assertEqual(self.root.grid_slaves(), [])
        self.assertEqual(b.grid_info(), {})
        b.grid_configure(row=0, column=0)
        info = b.grid_info()
        self.assertEqual(info['row'], self._str(0))
        self.assertEqual(info['column'], self._str(0))
        self.assertEqual(info['rowspan'], self._str(1))
        self.assertEqual(info['columnspan'], self._str(1))
        self.assertEqual(info['padx'], self._str(0))
        self.assertEqual(info['pady'], self._str(0))
        self.assertEqual(info['sticky'], '') 
Example #11
Source File: test_geometry_managers.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_grid_rowconfigure(self):
        with self.assertRaises(TypeError):
            self.root.grid_rowconfigure()
        self.assertEqual(self.root.grid_rowconfigure(0),
                         {'minsize': 0, 'pad': 0, 'uniform': None, 'weight': 0})
        with self.assertRaisesRegexp(TclError, 'bad option "-foo"'):
            self.root.grid_rowconfigure(0, 'foo')
        self.root.grid_rowconfigure((0, 3), weight=2)
        with self.assertRaisesRegexp(TclError,
                                     'must specify a single element on retrieval'):
            self.root.grid_rowconfigure((0, 3))
        b = tkinter.Button(self.root)
        b.grid_configure(column=0, row=0)
        if tcl_version >= (8, 5):
            self.root.grid_rowconfigure('all', weight=3)
            with self.assertRaisesRegexp(TclError, 'expected integer but got "all"'):
                self.root.grid_rowconfigure('all')
            self.assertEqual(self.root.grid_rowconfigure(0, 'weight'), 3)
        self.assertEqual(self.root.grid_rowconfigure(3, 'weight'), 2)
        self.assertEqual(self.root.grid_rowconfigure(265, 'weight'), 0)
        if tcl_version >= (8, 5):
            self.root.grid_rowconfigure(b, weight=4)
            self.assertEqual(self.root.grid_rowconfigure(0, 'weight'), 4) 
Example #12
Source File: test_geometry_managers.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_grid_columnconfigure(self):
        with self.assertRaises(TypeError):
            self.root.grid_columnconfigure()
        self.assertEqual(self.root.grid_columnconfigure(0),
                         {'minsize': 0, 'pad': 0, 'uniform': None, 'weight': 0})
        with self.assertRaisesRegexp(TclError, 'bad option "-foo"'):
            self.root.grid_columnconfigure(0, 'foo')
        self.root.grid_columnconfigure((0, 3), weight=2)
        with self.assertRaisesRegexp(TclError,
                                     'must specify a single element on retrieval'):
            self.root.grid_columnconfigure((0, 3))
        b = tkinter.Button(self.root)
        b.grid_configure(column=0, row=0)
        if tcl_version >= (8, 5):
            self.root.grid_columnconfigure('all', weight=3)
            with self.assertRaisesRegexp(TclError, 'expected integer but got "all"'):
                self.root.grid_columnconfigure('all')
            self.assertEqual(self.root.grid_columnconfigure(0, 'weight'), 3)
        self.assertEqual(self.root.grid_columnconfigure(3, 'weight'), 2)
        self.assertEqual(self.root.grid_columnconfigure(265, 'weight'), 0)
        if tcl_version >= (8, 5):
            self.root.grid_columnconfigure(b, weight=4)
            self.assertEqual(self.root.grid_columnconfigure(0, 'weight'), 4) 
Example #13
Source File: components.py    From SEM with MIT License 6 votes vote down vote up
def __init__(self, root, main_window, button_opt):
        ttk.Frame.__init__(self, root)
        
        self.root = root
        self.main_window = main_window
        self.current_files = None
        self.button_opt = button_opt
        
        # define options for opening or saving a file
        self.file_opt = options = {}
        options['defaultextension'] = '.txt'
        options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        options['initialdir'] = os.path.expanduser("~")
        options['parent'] = root
        options['title'] = 'Select files to annotate.'
        
        self.file_selector_button = ttk.Button(self.root, text=u"select file(s)", command=self.filenames)
        self.label = ttk.Label(self.root, text=u"selected file(s):")
        self.fa_search = tkinter.PhotoImage(file=os.path.join(self.main_window.resource_dir, "images", "fa_search_24_24.gif"))
        self.file_selector_button.config(image=self.fa_search, compound=tkinter.LEFT)
        
        self.scrollbar = ttk.Scrollbar(self.root)
        self.selected_files = tkinter.Listbox(self.root, yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.selected_files.yview) 
Example #14
Source File: Tkdnd.py    From BinderFilter with MIT License 6 votes vote down vote up
def test():
    root = Tkinter.Tk()
    root.geometry("+1+1")
    Tkinter.Button(command=root.quit, text="Quit").pack()
    t1 = Tester(root)
    t1.top.geometry("+1+60")
    t2 = Tester(root)
    t2.top.geometry("+120+60")
    t3 = Tester(root)
    t3.top.geometry("+240+60")
    i1 = Icon("ICON1")
    i2 = Icon("ICON2")
    i3 = Icon("ICON3")
    i1.attach(t1.canvas)
    i2.attach(t2.canvas)
    i3.attach(t3.canvas)
    root.mainloop() 
Example #15
Source File: Tkdnd.py    From oss-ftp with MIT License 6 votes vote down vote up
def test():
    root = Tkinter.Tk()
    root.geometry("+1+1")
    Tkinter.Button(command=root.quit, text="Quit").pack()
    t1 = Tester(root)
    t1.top.geometry("+1+60")
    t2 = Tester(root)
    t2.top.geometry("+120+60")
    t3 = Tester(root)
    t3.top.geometry("+240+60")
    i1 = Icon("ICON1")
    i2 = Icon("ICON2")
    i3 = Icon("ICON3")
    i1.attach(t1.canvas)
    i2.attach(t2.canvas)
    i3.attach(t3.canvas)
    root.mainloop() 
Example #16
Source File: Tkinter.py    From BinderFilter with MIT License 6 votes vote down vote up
def _test():
    root = Tk()
    text = "This is Tcl/Tk version %s" % TclVersion
    if TclVersion >= 8.1:
        try:
            text = text + unicode("\nThis should be a cedilla: \347",
                                  "iso-8859-1")
        except NameError:
            pass # no unicode support
    label = Label(root, text=text)
    label.pack()
    test = Button(root, text="Click me!",
              command=lambda root=root: root.test.configure(
                  text="[%s]" % root.test['text']))
    test.pack()
    root.test = test
    quit = Button(root, text="QUIT", command=root.destroy)
    quit.pack()
    # The following three commands are needed so the window pops
    # up on top on Windows...
    root.iconify()
    root.update()
    root.deiconify()
    root.mainloop() 
Example #17
Source File: main.py    From PiPark with GNU General Public License v2.0 6 votes vote down vote up
def escapePressHandler(self, event):
        """Handle ESCAPE key events. """
        
        if self.__is_verbose: print "ACTION: ESCAPE key pressed."
        
        
        # if the camera is previewing -> stop the preview
        if self.__camera and self.__preview_is_active:
            self.__camera.stop_preview()
            self.__preview_is_active = False
            if self.__is_verbose: print "INFO: Camera preview stopped. "
            
            # reset focus to application frame
            self.focus_set()
    
    # --------------------------------------------------------------------------
    #  Button Press Events
    # -------------------------------------------------------------------------- 
Example #18
Source File: GUI.py    From nekros with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _unbound_to_mousewheel(event, widget):
    if platform.system() == 'Windows' or platform.system() == 'Darwin':
        widget.unbind_all('<MouseWheel>')
        widget.unbind_all('<Shift-MouseWheel>')
    else:
        widget.unbind_all('<Button-4>')
        widget.unbind_all('<Button-5>')
        widget.unbind_all('<Shift-Button-4>')
        widget.unbind_all('<Shift-Button-5>') 
Example #19
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_grid_configure_ipady(self):
        b = tkinter.Button(self.root)
        with self.assertRaisesRegexp(TclError, 'bad ipady value "-1": '
                                     'must be positive screen distance'):
            b.grid_configure(ipady=-1)
        b.grid_configure(ipady=1)
        self.assertEqual(b.grid_info()['ipady'], self._str(1))
        b.grid_configure(ipady='.5c')
        self.assertEqual(b.grid_info()['ipady'],
                self._str(int_round(pixels_conv('.5c') * self.scaling))) 
Example #20
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_grid_configure_ipadx(self):
        b = tkinter.Button(self.root)
        with self.assertRaisesRegexp(TclError, 'bad ipadx value "-1": '
                                     'must be positive screen distance'):
            b.grid_configure(ipadx=-1)
        b.grid_configure(ipadx=1)
        self.assertEqual(b.grid_info()['ipadx'], self._str(1))
        b.grid_configure(ipadx='.5c')
        self.assertEqual(b.grid_info()['ipadx'],
                self._str(int_round(pixels_conv('.5c') * self.scaling))) 
Example #21
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 #22
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_grid_configure_column(self):
        b = tkinter.Button(self.root)
        with self.assertRaisesRegexp(TclError, 'bad column value "-1": '
                                     'must be a non-negative integer'):
            b.grid_configure(column=-1)
        b.grid_configure(column=2)
        self.assertEqual(b.grid_info()['column'], self._str(2)) 
Example #23
Source File: test_geometry_managers.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_grid_configure(self):
        b = tkinter.Button(self.root)
        self.assertEqual(b.grid_info(), {})
        b.grid_configure()
        self.assertEqual(b.grid_info()['in'], self.root)
        self.assertEqual(b.grid_info()['column'], self._str(0))
        self.assertEqual(b.grid_info()['row'], self._str(0))
        b.grid_configure({'column': 1}, row=2)
        self.assertEqual(b.grid_info()['column'], self._str(1))
        self.assertEqual(b.grid_info()['row'], self._str(2)) 
Example #24
Source File: test_widgets.py    From oss-ftp with MIT License 5 votes vote down vote up
def create2(self):
        p = self.create()
        b = tkinter.Button(p)
        c = tkinter.Button(p)
        p.add(b)
        p.add(c)
        return p, b, c 
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.Button(self.root, **kwargs) 
Example #26
Source File: WindowFrame.py    From Diabetic-Retinopathy-Feature-Extraction-using-Fundus-Images with GNU General Public License v3.0 5 votes vote down vote up
def NextWindow(self, methodToExecute):
        listWF = list(self.MainObj.listOfWinFrame)
        print("Size: ", len(listWF))
        
        if (self.method == 0 or self.callingObj == 0):
            print("Calling Method or the Object from which Method is called is 0")
            return
        
        if (self.method != 1):
            methodToExecute()                   ## Executing the Method for "Next Frame" 
        
        if (self.callingObj == self.MainObj.ExEd):
            img = self.MainObj.ExEd.getImage()  ## Getting Result for "Next Frame"
        elif (self.callingObj == self.MainObj.BV):
            img = self.MainObj.BV.getImage()  ## Getting Result for "Next Frame"
        else:
            print ("Error: No specified object for getImage() function")
            
        jpgImg = Image.fromarray(img)
        current = 0
        
        for i in xrange(len(listWF)):       ## Hiding all Frames
            listWF[i].hide()
            if (listWF[i] == self):
                current = i
                print (current)
                

        if (current == len(listWF)-1):    ## Disable the "Next Button" of last frame
            print ("Last")
            listWF[current].unhide()
            listWF[current].setImage(jpgImg)
            listWF[current].displayImage()
            self.btnNext['state'] = 'disable'
        else:                               ## unhide the Next Frame
            listWF[current+1].unhide()
            listWF[current+1].setImage(jpgImg)
            listWF[current+1].displayImage()
            
        print(current, " is done!! _Remove me_") 
Example #27
Source File: nsf2x.py    From nsf2x with GNU General Public License v2.0 5 votes vote down vote up
def configStop(self, AllowButton=True, ActionText=_("Stop")):
        """Gui Stop Button Configuration"""
        self.chooseNsfButton.config(state=tkinter.DISABLED)
        self.chooseDestButton.config(state=tkinter.DISABLED)
        self.entryPassword.config(state=tkinter.DISABLED)
        if AllowButton:
            self.startButton.config(text=ActionText, state=tkinter.NORMAL)
        else:
            self.startButton.config(text=ActionText, state=tkinter.DISABLED)
        self.optionsButton.config(state=tkinter.DISABLED)
        self.formatTypeEML.config(state=tkinter.DISABLED)
        self.formatTypeMBOX.config(state=tkinter.DISABLED)
        self.formatTypePST.config(state=tkinter.DISABLED) 
Example #28
Source File: asktext.py    From textext with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_buttons(self):
        """Creates and connects the Save, Cancel and Preview buttons"""

        spacing = 0

        button_box = Gtk.HButtonBox()

        button_box.set_border_width(5)
        button_box.set_layout(Gtk.ButtonBoxStyle.EDGE)
        button_box.set_spacing(spacing)

        self._cancel_button = Gtk.Button(stock=Gtk.STOCK_CANCEL)
        self._cancel_button.set_tooltip_text("Don't save changes (ESC)")
        button_box.add(self._cancel_button)

        self._preview_button = Gtk.Button(label="Preview")
        self._preview_button.set_tooltip_text("Show/ update preview (CTRL+P)")
        button_box.add(self._preview_button)

        self._ok_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
        self._ok_button.set_tooltip_text("Update or create new LaTeX output (CTRL+RETURN)")
        button_box.add(self._ok_button)

        self._cancel_button.connect("clicked", self.cb_cancel)
        self._ok_button.connect("clicked", self.cb_ok)
        self._preview_button.connect('clicked', self.update_preview)

        return button_box 
Example #29
Source File: backend_tkagg.py    From Computable with MIT License 5 votes vote down vote up
def _Button(self, text, file, command):
        file = os.path.join(rcParams['datapath'], 'images', file)
        im = Tk.PhotoImage(master=self, file=file)
        b = Tk.Button(
            master=self, text=text, padx=2, pady=2, image=im, command=command)
        b._ntimage = im
        b.pack(side=Tk.LEFT)
        return b 
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 getListOfWinFrame():
        return self.listOfWinFrame


### Browse Button for Welcome Frame ###