Python GUI with Tkinter – 8 – Using Classes

Python

Video is ready, Click Here to View ×


Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

23 thoughts on “Python GUI with Tkinter – 8 – Using Classes

  1. Didn't work for me first time round, but after 10 minutes I came up with this:

    from tkinter import *
    root = Tk()

    def print_message():
    print("Wow this actually worked.")

    frame = Frame(root)
    frame.pack()

    print_button = Button(frame, text="Print Message", command=print_message)
    print_button.pack(side=LEFT)

    quit_button = Button(frame, text="Quit", command=frame.quit)
    quit_button.pack(side=LEFT)

    root.mainloop()

  2. Wow so i am the only one that paused the video when he said he's gonna make 2 buttons that print and quit? I had an idea in my mind to use raise SystemExit

    Def nameprinter():
    Print(something)

    Def quiter():
    raise SystemExit

    Button1 = Button(root, text="nameprinter", command=nameprinter

    Button2 = Button(root, text="exit", command=quiter)

  3. Honestly, i dont see many difference from using class and not, it's just more organized, but you still have to write the function "Print message" and all the statements to initialize the frame

  4. Eyyy really well explained!! I've just have a doubt: if I wanna run the class in a thread, what I should put inside the definition of the function run?? 'def run(self): ¿? '
    Thanks 😉

  5. I have no clue what the fuck happened in this video. I understood every one of your past video's in this tutorial series, but now I just don't get it.

  6. I'm getting just blank frame without any buttons.how can get the buttons in the frame.
    I have copied the code as it is showed,
    CODE:

    from tkinter import *

    class open_quit:

    def __init__(self,master):

    frame = Frame(master)
    frame.pack

    self.msg_button = Button(frame,text='msg_button',command = self.print_msg) #when frame is replaced by master the button was displayed in the frame
    self.msg_button.pack(side= LEFT)

    self.quit_button = Button(frame,text='quit_button',command = frame.quit)
    self.quit_button.pack(side= LEFT)

    def print_msg(self):
    print("Well,It's worked")

    root = Tk()

    b = open_quit(root)

    root.mainloop()

    here one more problem when I replaced Frame with master it worked.what is problem in it ??

  7. hey Bucky Roberts i'm getting error on this class program please help me

    my program is:

    from tkinter import *

    class ButtonWindow:
    def __int__(self,master):#here we use master name it create second window
    frame = Frame(master)
    frame.pack()

    self.print_button = Button(frame, text= "Print messege", command = self.print_messege) #now we have to create some button on "button_window"
    self.print_button.pack(side=LEFT)

    self.quit_button = Button(frame, text= "Quit", command = frame.quit) #This is create quit button and we use a command "frame.quit" for break loop or close window
    self.quit_button.pack(side=LEFT)
    def print_messege(self):
    print("Button is working")
    root = Tk()
    ButtonWindow(root)
    root.mainloop()# here note that root1 is main window or first window

    Error message is:

    Traceback (most recent call last):
    File "C:/Users/DELL/PycharmProjects/new1/using_classes.py", line 17, in <module>
    ButtonWindow(root)
    TypeError: object() takes no parameters

    Process finished with exit code 1

  8. Just want to take a second to thank you dude! I've been learning Python for a while now and i've always been put off by 'Classes', purely because in other videos no one explained the use of them or what '__init__', actually does.

    So good job with the videos man, your 're a good teacher!

  9. If it says: "AttributeError: NameOfYourClass object has no attribute 'printMessage' " then do this one simple step:

    You cut your def printMessage and then paste it before def __init__!

    It worked for me! =)
    P.S. NameOfYourClass is name of your class. It will be most likely different of mine.
    Sorry for pour English!

Leave a Reply

Your email address will not be published. Required fields are marked *