0

I'm trying to create a frame with 3 frames inside using class (to add more frames in the future with ui button).First time I'm using class. It gives me error, and I can't find in google what is the problem. It seems can't access variables stored in class object after creation, but ui builds correctly.(Error after pressing button)

from tkinter import *

window = Tk()

names = [["123","456","789"]]

window.title("123")
window.geometry('400x250')
window.resizable(False, False)

def savebuttonfunc():
    for i in names:
        if type(i) != 'list':
            i = []
        i[0] = title.entry.get()
        i[1] = description.entry.get()
        i[2] = voicechat.entry.get()


top = Frame(window)
top.grid(row=0)
titletop = Label(top, text="Top")
titletop.grid(column=0, row=0, padx=(5, 10))
savebutton = Button(top, text="Save", command = savebuttonfunc)
savebutton.grid(column=3, row=0, padx=(5, 10))

eb = Frame(window)
eb.grid(row=1)

class Entries:
    def __init__(self, column, width, text, id):
        self = Frame(eb)
        self.grid(row=1,column=column, padx=(5, 10))
        self.string_var = StringVar()
        self.entry = Entry(self, textvariable=self.string_var, width=width)
        self.entry.grid(row=1)
        if not names[0][id]:
            self.string_var.set('123')
        self.string_var.set(names[0][id])
        self.txt = Label(self, text=text)
        self.txt.grid(row=0)

title = Entries(1,10, 'Title', 0)
description = Entries(2,25, 'Description', 1)
voicechat = Entries(3,7, 'VoiceChat', 2)

window.mainloop()
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\_DW\story of\Python\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:\Users\delor\AppData\Roaming\JetBrains\PyCharmCE2021.1\scratches\scratch_2.py", line 15, in savebuttonfunc
    i[0] = title.entry.get()
AttributeError: 'Entries' object has no attribute 'entry'

0 Answers0