Python 3 Programming Tutorial – Tkinter adding buttons

Home/Programming Video Tutorials/Python Video Tutorials/Python 3 Programming Tutorial – Tkinter adding buttons

Python 3 Programming Tutorial – Tkinter adding buttons

FavoriteLoadingAdd to favorites

In this tutorial, we cover adding buttons to our tkinter window. Adding buttons is very simple, and we can also begin to add events to these buttons.

Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/

Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

http://seaofbtc.com
http://sentdex.com
http://hkinsley.com

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

By | 2017-06-01T00:28:48+00:00 June 1st, 2017|Python Video Tutorials|26 Comments

26 Comments

  1. MinecraftWiz98 June 1, 2017 at 12:31 am - Reply

    FIRST

  2. McSkeeto June 1, 2017 at 12:33 am - Reply

    3:34 FFS WELL DONE… huh we cant see it

  3. DataDestroyer June 1, 2017 at 12:33 am - Reply

    I have the same problem and it’s pretty frustrating how come it’s not changing the title or putting the button. I am confused please help

  4. Greg Lowe Design June 1, 2017 at 12:34 am - Reply

    Just an FYI and suggestion: The title of this video is "Python 3 Programming Tutorial – Tkinter adding buttons" and is missing the #Number. It would be great to know which number I am on, so I can go look for the following sequential video.

  5. Harrison Mustapha June 1, 2017 at 12:40 am - Reply

    HELP! my button does not work. i have the right code. i am using python 3.5.1. Help me to show it!

  6. Mohamed Gabr June 1, 2017 at 12:42 am - Reply

    I can see the form window but no buttons. Also I got this traceback:
    Traceback (most recent call last):
    File "E:PythonSentdexExamples28TkinterButton.py", line 30, in <module>
    app=window(root)# our frame is going to be our root
    File "E:PythonSentdexExamples28TkinterButton.py", line 9, in __init__
    Frame.___init__(self, master)
    AttributeError: type object ‘Frame’ has no attribute ‘___init__’

    Is there a solution for this?
    Thank you 🙂

  7. Tsukasa1929 June 1, 2017 at 12:45 am - Reply

    when i use your method it doesn’t work, i’m using 3.4.4, i did like this:

    ##class Window(Frame):
    ##
    ## def ___init__(self):
    ## Frame.__init__(self)
    ##
    ## self.master = master
    ##
    ## self.init_window()

    ## def init_window(self):
    ##
    ## self.master.title(‘GUI’)
    ##
    ## self.pack(fill=BOTH, expand=1)
    ##
    ## quitButton = Button(self, text=’Quit’)
    ##
    ## quitButton.place(x=0, y=0)

    root = Tk()

    root.geometry(‘400×300’)
    root.title(‘GUI’)
    quitButton = Button(root, text=’Quit’)
    quitButton.pack()
    quitButton.place(x=0, y=0)
    #app = Window(root)

    root.mainloop()

  8. nikhil yadav June 1, 2017 at 12:47 am - Reply

    +sentdex tkinter is not present by default? not downloading via pip as well

  9. Python 3.4 June 1, 2017 at 12:50 am - Reply

    Hey dude nice everything for so far but when i run it now i got the error unindent does not match any outer indentation level!
    Can you pls help

  10. alex kennedy June 1, 2017 at 12:50 am - Reply

    I am having trouble getting the new function to work. My code is:

    from tkinter import *

    class Window(Frame):

        def _init_(self, master = None):
            Frame._init_(self, master)
            self.master = master
            self.init_window()

        def init_window(self):
            self.master.title("GUI")
            self.pack(fill = BOTH, expand = 1)
            quitButton = Button(self,text = "Quit")
            quitButton.place(x = 10, y = 10)

    root = Tk()
    root.geometry("400×300")
    app = Window(root)
    root.mainloop()

    When I run this, the title does not change nor does the button appear in the window.
    I am using python 3.4.2

  11. Daniel Rojas June 1, 2017 at 12:54 am - Reply

    How can i make a image to act as a button?

  12. Amy Hayworth June 1, 2017 at 12:59 am - Reply

    My button isn’t showing up

  13. Patrick Patrick June 1, 2017 at 1:00 am - Reply

    can we use % for x and y? for example (x = 50% ,y = 50%) ?

  14. jake mathew June 1, 2017 at 1:00 am - Reply

    HI, i typed your exact code and the button is not appearing. please tell me why? thanks alot for your videos and help.

    from tkinter import *

    class Window(Frame):
                def init(self,master=None):
                      Frame.init(self,master)

                      self.master=master
                      self.init_window()

                def init_window(self):
                      self.master.title("GUI")
                      self.pack(fill=BOTH, expand=1)
                      quitButton= Button(self, text="Quit")
                      quitButton.place(x=0, y=0)
                      

    root = Tk()
    root.geometry("400×300")
    app = Window(root)

    root.mainloop()

  15. Allan Perez June 1, 2017 at 1:01 am - Reply

    one question: what does ‘.master’ or ‘.title’ or ‘.mainloop’ or ‘self’ do? I mean, why do we put it here, where does it come? and what does it do?

  16. Faris Amirmudin June 1, 2017 at 1:06 am - Reply

    can you explain this line deeper. thank you

    self.pack(fill=BOTH, expand=1)

  17. Mohamed Gabr June 1, 2017 at 1:06 am - Reply

    I trıed to wrıte the codeç After some trıals, I decided to copy your code. now, I see the window but not the button. Do you know why that? 🙂

  18. Rene Grootscholten June 1, 2017 at 1:12 am - Reply

    Hi…. This is great help.but…..
    I added a text field on the window and I like the button to do something with it…
    It seems I’m missing a reference because several errors appears

    from tkinter import *

    class Window(Frame):

    def __init__(self, master=None):
    Frame.__init__(self, master)
    self.master = master
    self.init_window()

    def init_window(self):
    self.master.title("GUI")
    self.pack(fill=BOTH, expand=1)
    menu = Menu(self.master)
    self.master.config(menu=menu)
    file = Menu(menu)
    file.add_command(label="Exit", command=self.client_exit)
    menu.add_cascade(label="File", menu=file)

    debugInfo = Text(self, Height=7, width=90)
    debugInfo.pack()
    debugInfo.insert(END, "Hallo world")

    def client_exit(self):
    debugInfo.insert(END, "closing Hallo world")
    exit()

    root = Tk()
    root.geometry("400×300")

    app = Window(root)
    root.mainloop()

  19. lklash June 1, 2017 at 1:14 am - Reply

    try this. it closes the window :

    from tkinter import *

    master = Tk()

    def closewindow() :
    exit()

    button = Button(master, text = ‘hi’, command=closewindow)

    button.pack()

    btw, do on new window

  20. Paul June 1, 2017 at 1:15 am - Reply

    any chance u can do some more tkinter tuts from begginer up please 🙂

  21. devesh bajaj June 1, 2017 at 1:15 am - Reply

    how to add some font and text and direct images in window

  22. Jay Snieder June 1, 2017 at 1:19 am - Reply

    Hi, my button doesn’t show. I have copied all the codes. I am using python 3.4.3.
    please help me.

  23. Pranav Mishra June 1, 2017 at 1:20 am - Reply

    every time i type my code and then run module, python shell also opens along with the tkinter window. in the window i see this is not the case. anyone ?

  24. ElAnill0 June 1, 2017 at 1:22 am - Reply

    Hi I keep getting a syntax error with my code when I use the 
    self.pack(fill=BOTH, expand=1)

    Please help, thank you in advance.

  25. Carlos Almegure June 1, 2017 at 1:25 am - Reply

    My button isn’t showing

  26. Mohammadreza Rajabi June 1, 2017 at 1:26 am - Reply

    Hi it is very good series but i am wondering if you could share some clips to explain detail usage of QT designer for complex GUI development or even maybe project based development for a series. I am really interested to learn it but there is very very less learning material about it.Would be great if you consider it 

Leave A Comment

*