I have an existing Python 3 program which I wrote quick-and-dirty without any object-oriented techniques (it was my first Python program). It's time I clean it up, and I'm having problems making tkinter work in my classes.
Here is a simplified example. It is only attempting to place a ttk.Entry widget into the class, which is inheriting from ttk.Frame:
import tkinter as tk
from tkinter import ttk
class MyClass(ttk.Frame):
def __init__(self, parent):
self.frame = ttk.Frame(parent)
# Entry widget
self.entValue = ttk.Entry(self.frame)
self.entValue.grid(column=0, row=0)
# tkinter init
root = tk.Tk()
# Make the class instance and place it
test = MyClass(root)
test.grid(column=0, row=0)
It gives me the following error:
Traceback (most recent call last):
File "{path_to_code}/so.py", line 17, in <module>
test.grid(column=0, row=0)
File "{path_to_python}\Python35-32\lib\tkinter\__init__.py", line 2072, in grid_configure
self.tk.call(
AttributeError: 'MyClass' object has no attribute 'tk'
What am I missing?