[source code] Python GUI with Tkinter - 8 - Using Classes

+1 Bucky Roberts · September 13, 2014

from tkinter import *


class BuckysButtons:

    def __init__(self, master):
        frame = Frame(master)
        frame.pack()

        self.printButton = Button(frame, text="Print Message", command=self.printMessage)
        self.printButton.pack(side=LEFT)

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

    def printMessage(self):
        print("Wow, this actually worked!")


root = Tk()
b = BuckysButtons(root)
root.mainloop()

Post a Reply

Replies

Oldest  Newest  Rating
0 Marcin Wronecki · September 13, 2014
For me 
frame.quit


doesn't work, only add one command prompt ">>>". Frame is still on switch on.  Any advice ? :)
0 Jörg Bummer · November 20, 2014
doesn't work for me, too.
Can someone explain why frame.quit doesn't work.

to make the program ready to work change the line with the following



self.quitButton = Button(frame, text="Quit", command=root.destroy)
  • 1

Python

107,028 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator