Object Oriented Programming Crash course with Python 3 – Tkinter tutorial Python 3.4 p. 2

///Object Oriented Programming Crash course with Python 3 – Tkinter tutorial Python 3.4 p. 2

Object Oriented Programming Crash course with Python 3 – Tkinter tutorial Python 3.4 p. 2

FavoriteLoadingAdd to favorites

Tkinter GUI TutorialPlaylist: http://www.youtube.com/playlist?list=PLQVvvaa0QuDclKx-QpC9wntnURXVJqLyk

Python 3 basics tutorial: http://youtu.be/oVp1vrfL_w4?list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

This tutorial video serves two purposes. One: It is a rough crash course into object oriented programming. Second: It is the 2nd part in our tkinter GUI development series.

Here we talk about how object oriented programming works, with classes __init__, self, parent, and all this other nonsense.

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

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

By |2017-05-30T00:25:21+00:00May 30th, 2017|Python Video Tutorials|49 Comments

49 Comments

  1. Bharath Sivakumar May 30, 2017 at 12:27 am - Reply

    On mine it says that self isn’t defined

  2. Abhishek Honnavalli Puttaiah May 30, 2017 at 12:29 am - Reply

    Thank for comprehensive tutorial. Could you please assist me ?
    I want
    to communicate between class A and class B in separate file C (Just
    script). I am instantiating class B and A in C but I want to use
    instantiated B in A.
    How to make this possible ?

  3. Steven Nguyen May 30, 2017 at 12:30 am - Reply

    Why do you use square brackets after ‘frames’

  4. Maroun Nasr May 30, 2017 at 12:33 am - Reply

    Hi! great video! I was wondering if you could explain some things in more detail for me!

    What is meant with cont and the two parameters parent and controller

  5. finn quail May 30, 2017 at 12:34 am - Reply

    _undercore_

  6. Walter Noah May 30, 2017 at 12:35 am - Reply

    Thanks so much for this! I have been looking for weeks for how to do this

  7. Darkaero May 30, 2017 at 12:38 am - Reply

    Thank you for making these videos, the way you teach is great. it’s very informative and you take just the right amount of time to explain things so that, not only does it not get boring, the subject is easy to follow along and digest. Great work!

  8. morphman86 May 30, 2017 at 12:42 am - Reply

    I started in Basic on a VIC-20 when I was 7 years old, went on to C++ when I was 13, continued to JAVA, then PHP, then C#. After about 23 years of programming, I finally tried Python.

    This is by far the easiest one to use, and with tkinter it’s the one requiring the least amount of code to get a window up and running and doing what I want it to do.

    So when people say tkinter isn’t the right way to go, you can tell them to stuff it, tkinter is awesome!

  9. BadGamePlayerPl May 30, 2017 at 12:44 am - Reply

    What’s ur name, Sentdex? Just askin’

  10. Dave Longcake May 30, 2017 at 12:44 am - Reply

    I simply get invalid identifier error message even copying this word for word… on any version of python and i have no idea where it is

  11. Jackson Weidmannmann May 30, 2017 at 12:45 am - Reply

    I’m getting an error that says:

    self.frames[StartPage] = frame
    TypeError: ‘tuple’ object does not support item assignment

    What did I do wrong?

  12. Al K May 30, 2017 at 12:45 am - Reply

    +sentdex, hi, there is a typo in your website for p.2, in the full code section- text for label says "Start Page" even though in the previous section it was correct " This is the start page"

  13. Ranjeet Singh May 30, 2017 at 12:46 am - Reply

    please tell me how to make exe file in python3.5

  14. Davis Ureña May 30, 2017 at 12:46 am - Reply

    Thanks for uploading this instructives. I’m a begginer at Python; and I really can’t grasp the concept of object oriented programming and why is it better than just lines of codes (since all I have ever done are matlab scripts or solve engineering equations). This video kind of opened my eyes when you did app.mainloop() at the end. Still would appreciate any resource that help me do the transition from scripts to object oriented mindset.

  15. BadGamePlayerPl May 30, 2017 at 12:46 am - Reply

    there’s a bit easier method to initialize the class:

    from tkinter import *

    class App(Frame):
    def __init__(self, master):
    self.grid()
    super(App, self).__init__(master)

    then the window:
    root = Tk()
    application = App(root)
    root.mainloop()
    But if u prefer that method, no problem

  16. Geek Zone May 30, 2017 at 12:47 am - Reply

    #Code cheat sheet – Like this comment so that everyone can see
    import tkinter as tk
    LARGE_FONT=("Verdana", 12)
    class SeaofBTCapp (tk.Tk):
    def __init__(self,*args,**kwargs):
    tk.Tk.__init__(self, *args, **kwargs)
    container = tk.Frame(self)
    container.pack(side="top", fill="both", expand = True)

    container.grid_rowconfigure(0, weight=1)
    container.grid_columnconfigure(0, weight=1)

    self.frames = {}
    frame = StartPage(container, self)
    self.frames[StartPage] = frame
    frame.grid(row=0, column = 0, sticky="nsew")
    self.show_frame(StartPage)

    def show_frame(self,cont):
    frame = self.frames[cont]
    frame.tkraise()

    class StartPage(tk.Frame):
    def __init__(self, parent, controller):
    tk.Frame.__init__(self,parent)
    label = tk.Label(self, text="Start Page", font=LARGE_FONT)
    label.pack(pady=10, padx=10)

    app= SeaofBTCapp()
    app.mainloop()

  17. Simon Mahns May 30, 2017 at 12:47 am - Reply

    actually a dad

  18. Abhishek Joshi May 30, 2017 at 12:48 am - Reply

    you are doing a wonderful job with your tutorials !! Keep it up Sir!! Hats off to you

  19. Brandon E May 30, 2017 at 12:50 am - Reply

    Finally, someone who explains his thought process line by line. Thank you.

  20. zeekgill May 30, 2017 at 12:50 am - Reply

    Thanks a lot for this extremely helpful tutorial. However, I do encounter a problem when changing the code from pack to grid method. And I’m not sure where I’m going wrong.
    I would like to have labels placed next to input textboxes, but whenever I use label.grid() or button.grid() method, I get the following error:

    _tkinter.TclError: cannot use geometry manager grid inside .690697562544.690824114976 which already has slaves managed by pack

    I tried replacing all the pack() methods with grid(), but it the error still persists. Any help in this regard would be greatly appreciated.

  21. Alan K May 30, 2017 at 12:50 am - Reply

    Hi there,

    Why is it that some code examples on some websites that do the exact same thing don’t use certain lines of code, like the dictionary?

  22. August Languepin May 30, 2017 at 12:53 am - Reply

    so much code = so much fun

  23. stokes288 May 30, 2017 at 12:53 am - Reply

    this dude reminds me of jared dunn from silicon valley

  24. Sarah Lavoie May 30, 2017 at 12:54 am - Reply

    You are exactly what us tkinter newcomers need! You have explained fundamental concepts that no one else bothered to and are very easy to understand. Thank you.

  25. THE GNOME2 May 30, 2017 at 12:55 am - Reply

    tracked by the NSA?

  26. Huiming Song May 30, 2017 at 12:57 am - Reply

    thanks a lot for the wonderful video. may I ask a question, why use " frame = StartPage(container, self) "? rather than "frame = StartPage(self, container) "?

  27. Nigel Hall May 30, 2017 at 12:59 am - Reply

    I see that when you switch frames in this method the frames are always going to be the same as when they first loaded. I was wondering if there was a way to reload each frame as you switch to them… Any help on that would be great. You have a really good channel btw

  28. Ibrahim ahmed May 30, 2017 at 1:00 am - Reply

    whats the difference with container and self when you write "frame = StartPage (container,self)"

  29. Andrew Crews May 30, 2017 at 1:01 am - Reply

    @sentdex wouldn’t it be better form to use super().__init__(self,parent) instead of tk.Frame?

  30. Envaya May 30, 2017 at 1:01 am - Reply

    I really didn’t like this. Dont recommend watching this video for people who want to learn the basics of OOP (classes, objects) because it’s 99% about creating GUI.

  31. Nico Autia May 30, 2017 at 1:03 am - Reply

    I kinda lost it at around 6:00 when you started explaining what "self" means. I can program some small stuff with Python, but I never really got the hang of OOP. Can anyone suggest a good and short introduction to that? Other than that, I really like your way of explaining things. I guess if I was a little bit further on this topic, I could take a lot more from this. Thanks for the video

  32. len 114602 May 30, 2017 at 1:03 am - Reply

    Wow, Python is truly the epithet of OOP

  33. Augusto Oviedo May 30, 2017 at 1:03 am - Reply

    +sentdex I wanna say Thank you for this tutorial and Happy new Year 2017. I consider myself a Python Begginer, even when I find your Tutorial very Rich, it has been very tough for me because I am the kind of person how tries understands the reason of your code structure, I finally did it and now I am for the chapter 4 😀

  34. Humayun Ahmed May 30, 2017 at 1:03 am - Reply

    Great Video. I have a question. Can anyone explain why self is the second parameter in the startpage class?. Container is just an empty frame.
    The startpage class inherits from the Frame class and so it is basically creating a frame with that label. Am I right when I say that the container instance is stored in the parent parameter in __init__ method in start page? if so, what is controller doing?.

    Any help would be appreciated. Thankyou

  35. Chet Los May 30, 2017 at 1:04 am - Reply

    Almost said "irregardless" at 11:30, eh? Great tutorial, but that part had me rolling. Thanks for taking the time to make this.

  36. Dang, man May 30, 2017 at 1:07 am - Reply

    Even as someone who understands OOP, I had a lot of ‘a ha’ moments during this vid. Thanks man…

  37. CognitiveBarry May 30, 2017 at 1:10 am - Reply

    I get this error: http://pastebin.com/NSGyKP8i

    my code is as follows: http://pastebin.com/RY2JT7fh

    If anyone can help please do so.

  38. Tim Lawman May 30, 2017 at 1:11 am - Reply

    Hi, any advice on recording sound such as settings of the mic. I use a free screen caster and then use MovieMakers narrate feature. Is this good enough? What do you use to reduce background sound? Does a better mic than basic Logitech USB mic make a big difference?

  39. Gon Nespral May 30, 2017 at 1:12 am - Reply

    yuy

  40. Daniel Rojas May 30, 2017 at 1:14 am - Reply

    So I try to run that (exact same code) and it pops nothing, but when i try to close the shell it ask me if I want to kill the program which is still running.
    Working on python 3.5.1
    Mac OS X

  41. Patricia Garcia May 30, 2017 at 1:14 am - Reply

    Hello!!.
    I want to Adding a Menu at Startpage:

    Please help me with this error:

    tk.Frame.config(tk.Frame.menu=menubar)
    ^
    SyntaxError: keyword can’t be an expression

    class StartPage(tk.Frame):

    def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.controller = controller
    #Adding a menu
    menubar = tk.Menu(self)
    mantmenu=tk.Menu(menubar,tearoff=0)
    mantmenu.add_command(label="Usuarios",command=lambda:popupmsg("Not suppoorted just yet"))
    mantmenu.add_separator()
    mantmenu.add_command(label="Exit",command=quit)
    menubar.add_cascade(label="Mantenimiento de Base de Datos",menu=mantmenu)
    tk.Frame.config(tk.Frame.menu=menubar)

    label = tk.Label(self, text="This is the start page", font=TITLE_FONT)
    label.pack(side="top", fill="x", pady=10)

    button1 = tk.Button(self, text="Go to Page One",
    command=lambda: controller.show_frame("PageOne"))
    button2 = tk.Button(self, text="Go to Page Two",
    command=lambda: controller.show_frame("PageTwo"))
    button1.pack()
    button2.pack()

    ”’
    the line:

    tk.Frame.config(tk.Frame.menu=menubar) Not added to the menu at frame

    this neither:

    self.config(self. menu=menubar)
    ”’

    What i can do?
    Thanks!

  42. Vinicius Syl May 30, 2017 at 1:15 am - Reply

    So happy to find this awesome tutorial series. Thanks very much!

  43. Element Finland May 30, 2017 at 1:16 am - Reply

    Yeaaaaaah… I think i’ll just stick to electron lmao

  44. EddonahRae Aurelio May 30, 2017 at 1:16 am - Reply

    What if you add an entry box on to on of the classes, do you use say:self = Tk()e = tk.Entry(self)
    e.pack()

    e.focus_set()???Or is there any suitable code to use?Thank you so much.

  45. G G May 30, 2017 at 1:18 am - Reply

    running code (copied from site) works on windows but on linux I get this
    Traceback (most recent call last):
    File "…/seaOfBTCapp/tkinter.py", line 1, in <module>
    import tkinter as tk
    File "…./seaOfBTCapp/tkinter.py", line 5, in <module>
    class SeaofBTCapp(tk.Tk):
    AttributeError: ‘module’ object has no attribute ‘Tk’ in pycharm i can see tk.Tk class

  46. Juan José May 30, 2017 at 1:18 am - Reply

    quiero aprender alguna interfaz gráfica pero no sé cuál sea la mejor? tkinter, pyQT?
    I want to learn some graphical interface but I do not know which one is the best? Tkinter, pyQT?
    what dou you recommend?

  47. monawoka97 May 30, 2017 at 1:18 am - Reply

    Is there a website with tkinter documentation similiar to pygame? Pygame has some amazing documentation

  48. McCreepers 26 May 30, 2017 at 1:18 am - Reply

    why does t say kwargs i not defined

  49. SogMosee May 30, 2017 at 1:20 am - Reply

    Where did you get the python jacket from?

Leave A Comment

*