Python 3 Programming Tutorial – tkinter module making windows

///Python 3 Programming Tutorial – tkinter module making windows

Python 3 Programming Tutorial – tkinter module making windows

FavoriteLoadingAdd to favorites

In this video, we begin discussion of the tkinter module. The tkinter module is a wrapper around tk, which is a wrapper around tcl, which is what is used to create windows and graphical user interfaces. Here, we show how simple it is to create a very basic window in just 8 lines. Here, we get a window that we can resize, minimize, maximize, and close!

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-05-01T12:23:38+00:00April 26th, 2017|Programming Video Tutorials, Python Video Tutorials|47 Comments

47 Comments

  1. The Physicist Cuber April 26, 2017 at 9:15 pm - Reply

    What ‘s master?

  2. Mohamed Gabr April 26, 2017 at 9:17 pm - Reply

    the code works and the window appears but there is a traceback message:

    Traceback (most recent call last):
    File "E:PythonSentdexExamples26TkinterWindow.py", line 16, in <module>
    app=window(root)# our frame is going to be our root
    File "E:PythonSentdexExamples26TkinterWindow.py", line 9, in __init__
    Frame.___init__(self, master)
    AttributeError: type object ‘Frame’ has no attribute ‘___init__’
    >>>

    Is there a way to handle this?
    Also how can I understand the __init__.py in the tkinter better?

    Thanks a lot 🙂

  3. B Saxon April 26, 2017 at 9:21 pm - Reply

    You make really good videos, thanks so much!

  4. Adam Fatyga April 26, 2017 at 9:21 pm - Reply

    What is this "self"?

  5. New Maz April 26, 2017 at 9:24 pm - Reply

    def__int__(self, master = None ): HELP invalid syntax

  6. Xu Bo April 26, 2017 at 9:24 pm - Reply

    I did it with two lines.

  7. Баяраагын Баянжаргал April 26, 2017 at 9:25 pm - Reply

    how to add tkinter module

  8. Marcel Homšak April 26, 2017 at 9:25 pm - Reply

    Thanks man

  9. Farzad Khadem April 26, 2017 at 9:27 pm - Reply

    I am an avid fan of your channel and specially this python 3 tutorial series and I have watched, followed and learned the content in all 39 tutorials prior to this, but I didn’t understand a thing in this tutorial. Can please you point me to some followup reading to help me understand the commands you used in the tutorial. Thanks

  10. Larry Murcia April 26, 2017 at 9:27 pm - Reply

    Hi, how you doing? I would like to ask for your help. it is about an easy program with tkinter. if it is posible, would you write your email, or contact to me please. I appreciate it. Thanks

  11. Nader Elmahdy April 26, 2017 at 9:27 pm - Reply

    What is the importance of the last two lines I removed them and he code still works.

  12. padraic1983 April 26, 2017 at 9:29 pm - Reply

    hey Sent. you’re awesome man. I love your explanations. currently in your Udemy course.

  13. Jamie Reason April 26, 2017 at 9:32 pm - Reply

    Great video looking forward to watching your next python videos.
    I typed in your code and run it but it gave me an error with the line:
        app = Window(root)
    I removed that line and run it again this time it popped up with a window, do i need to keep the line of code I initially got rid of or is there an alternative.
    An answer would be appreciated.

  14. Nalin Jain April 26, 2017 at 9:32 pm - Reply

    from tkinter import *
    root = Tk()
    master = Frame(root, borderwidth = 5, width=500, height=500)
    master.pack()

    boom 4 lines

    good job btw

  15. Ishan Mahajan April 26, 2017 at 9:36 pm - Reply

    from tkinter import *

    root = Tk()

    root.mainloop()

  16. sam bourke April 26, 2017 at 9:40 pm - Reply

    Hey man. Thanks for the awesome vid. just for future reference just stick to the coding and less on it’s origins 🙂

  17. CaliberJR April 26, 2017 at 9:41 pm - Reply

    hmmm, its come up with name ‘master’ is not defined

  18. AzironPlayz April 26, 2017 at 9:42 pm - Reply

    Mine doesn’t work, when I run it it points at the F in frame on the line where it says Frame.__init__(self, master) and says that it’s an unexpected indent, please help!

  19. Chetan Khaire April 26, 2017 at 9:42 pm - Reply

    Sir why don’t you create a window with 2 lines of code like import tkinter
    wn=tkinter.Tk(). Then to write 8 lines of code.

  20. sonic2kk April 26, 2017 at 9:43 pm - Reply

    Great tutorial! Love the idea of a Tkinter "mini series". I used Tkinter to create a GUI audio converter program (for conversion, I used a library called PyDub, which is a wrapper around FFMPEG. http://www.pydub.com/).

    I’m not entirely sure why, but a lot of people don’t like Tkinter. They would prefer use something like wxPython. Now, I’m wondering what the big deal is between them? I’ve read Stackoverflow people suggesting that you go you out of your way _not_ to use Tkinter. I think Tkinter is pretty amazing and an awesome choice for GUI. I had a lot of problems with Gtk on OS X, and wxPython had a lot of problems with versions other than 2.6.X or 2.7.X.  To top it all off: Tkinter is _built in_!! What do you think?

  21. Madhu Gayathri April 26, 2017 at 9:44 pm - Reply

    what to do if we found an error that tinkter module is not found??

  22. SuperCactusBro Games April 26, 2017 at 9:48 pm - Reply

    lol I am less than 12 years old but this is the best video ever 🙂

  23. Samuel April 26, 2017 at 9:49 pm - Reply

    Cool video like always!

  24. Rian Irawan Hariadi April 26, 2017 at 9:49 pm - Reply

    what a nice tutorial, Dex.. Thanks. I am developing now Python based for Web-application using GUI , maybe TkInter is the best option for it.. if I make a web-application with Tkinter can we deploy it to the cloud, to my website, so the app could be run everytime I log in into my website? Thanks – Rian Hariadi

  25. Samarjeet Saluja April 26, 2017 at 9:49 pm - Reply

    what do each of the lines of code actually do in the tkinter module?

  26. Jesus Issou April 26, 2017 at 9:49 pm - Reply

    Am i the only one to not really understand what the code lines mean in this video? Did i miss something?
    All i know is that it creates a window that’s for sure. Is it normal or i need to go back to basics or smt?

    EDIT I’m reading the lib __init__ file and it’s a little bit more clear now.

  27. Баяраагын Баянжаргал April 26, 2017 at 9:50 pm - Reply

    how to download tkinter module

  28. simon gross April 26, 2017 at 9:53 pm - Reply

    Your tutorials are extremely well explained. You are doing an absolutely brilliant job. Thanks!

  29. wilhelm paul martinez April 26, 2017 at 9:56 pm - Reply

    200th like!

  30. Faris Amirmudin April 26, 2017 at 9:58 pm - Reply

    hello sir, what do these lines mean actually??

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

  31. Wenwu Xu April 26, 2017 at 9:58 pm - Reply

    the tutorial is getting more and more interesting, thanks a lot again.

  32. 郑成功 April 26, 2017 at 10:01 pm - Reply

    Great! I don’t need to install extra things now. Thanks

  33. newSogn April 26, 2017 at 10:02 pm - Reply

    I looked for a while for this tkinter as a module, but I wanted to mention it is included with python in the install that would have been pertinent info lol…..having said that I love these videos!!!! I can knock out a few a day in like 20 minutes and learn a ton!!!

    seriously like a whole semester of content in like 3 hours and I don’t need to keep my notes as they are in the tutorials I did for this

  34. alemazzuca April 26, 2017 at 10:02 pm - Reply

    Is there any difference in importing everything or just a special thing from tkinter in terms of speed or functioning?

  35. Cláudia Silva April 26, 2017 at 10:02 pm - Reply

    I will just skip the part of apologizing for my possibly dumb question, but on minute 4:51 you’re creating a method within the class Window, but this method already exists on the parent class Frame. So why didn’t you creat an object in the class window and then with this object pick the method from the parent class? 

  36. Nils Pasman April 26, 2017 at 10:02 pm - Reply

    Just a small tip 😉
    You searched for ‘def tk’ (at 5:55). Probably ‘def tk(‘ would’ve brought you where you wanted to get.
    Same counts for finding paragraphs in the html-sourcecode (relating to prev.tuts 37 & 39): searching for ‘<p>’ (or maybe ‘<p’?) should bring a readable part into focus.

  37. jaime sastre April 26, 2017 at 10:03 pm - Reply

    Hello Sentdex,
    Nice video introducing Tkinter.
    I just want to make some simple suggestions to simplify code.

    Examples:

    ex1:
    # simplest: a little like what you do on the end of your example with:

    from tkinter import *
    root = Tk()
    root.mainloop() # both commands are enough to produce the Frame you can see on your video. the rest is not used.

    ex2:
    # more in the class idea:

    from tkinter import Frame

    class MyFrame(Frame):

    def __init__(self, master=None):
    super(MyFrame, self).__init__(master, width=320, heigh=240)
    self.master.title(" My first Frame") # optional the name
    self.pack() # to use the size in the constructor

    my_frame = MyFrame() # notice the difference
    my_frame.mainloop() # mainloop on Frame instance

  38. Thukydides April 26, 2017 at 10:07 pm - Reply

    Hi!
    You maybe want to make an annotation for the linux users who dont have python3-tk installed (like me, a minute ago :)).
    I really love your content.

  39. Jeremy Taylor April 26, 2017 at 10:08 pm - Reply

    Overall, this was excellent (like the 37 before it). However, it seemed like you made some leaps in terminology that you didn’t in previous videos. For example –  you started talking about " defining our initialization" like it was common language, but I don’t think that’d been discussed previously. Perhaps I’m just particularly inexperienced and most others would know what you mean, but that left me a bit confused. Otherwise, thanks for all your great work, man!

  40. F Con April 26, 2017 at 10:09 pm - Reply

    Right off the bat from watching, I have a question:  is "import Tkinter" and "from Tkinter import *" the same thing?  if so, why not just save yourself some typing and just put "import Tkinter"?

  41. Zulfiqar Ali April 26, 2017 at 10:10 pm - Reply

    how to download tkinter for python 2.7.11

  42. Cory Crow April 26, 2017 at 10:10 pm - Reply

    I love your videos, but I am not very smart at this stuff yet and I have a question. I have tried to run this code in Anaconda, and I tried a similar way in Pycharm and it hasn’t worked either way, I was wondering if you had any insight? I figured tinter should come with both versions, but it doesn’t seem to recognize it. Thanks.

  43. Danish Mikhail April 26, 2017 at 10:11 pm - Reply

    Hi I have a problem, what I did was "app = Window(root)" and it says that "name Window is not defined" any solutions?

  44. Sempoo April 26, 2017 at 10:11 pm - Reply

    +sentdex From where did you learn tkinter – can you point me to some good online documentation? Official Python Docs are too complicated for me. You are also using OOP here, but it seems slightly complicated too. Thanks for your work!

  45. Life April 26, 2017 at 10:13 pm - Reply

    you need to be more descriptive you are just tellimg us what to do and what to type in and flying through it

  46. Tom Rehnert April 26, 2017 at 10:13 pm - Reply

    hey there. I am using pycharm as my compiler and the window does not appear when run. I tried it out in regular IDLE and it works fine but I had the design and look of IDLE. is there a fix to my pycharm problem?

  47. Remus Lupine April 26, 2017 at 10:13 pm - Reply

    I just want to say this is the best tutorial for python that I have found across all of youtube. Great Job, you are awesome

Leave A Comment

*