Tkinter – Python 3.5

Tkinter – Python 3.5

In Python 3.x, Tkinter module is renamed to tkinter:

try:
    # Python 3.x
    from tkinter import *
except ImportError:
    # Python 2.x
    from Tkinter import *

class Application(Frame):

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

    def create_widgets(self):
        self.myButton = Button(self, text=Button Label)
        self.myButton.grid()

root = Tk()

root.title(Frame w/ Button)
root.geometry(200x200)

app = Application(root)
root.mainloop()

UPDATE changed the code to run both in Python 2.x, Python 3.x.

I found the answer….Thanks for the comments

class Application(Frame):

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

    def create_widgets(self):
        self.myButton = Button(self, text=Button Label)
        self.myButton.grid()

    root = Tkinter.Tk()

    root.title(Frame w/ Button)
    root.geometry(200x200)

    app = Application(root)
    root.mainloop()

Tkinter – Python 3.5

Leave a Reply

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