I am trying to create a simple timer in Python and am aiming to build the user interface using classes. I would like to use the classes to initialise user interface. Then in the main text of the body, I would like to add attributes using the .grid and .configure methods. But when I try to do this, the error: 'statInter' object has no attribute 'tk' appears.
I am a beginner in programming, but if I understand the error correctly the it results because the .grid and other Button methods are not inherited by my statInter (i.e. static interface) class. Is this correct? How do I solve this error? I trued inheriting the properties of Button class and even Tk class, but in the later case I get an infinite loop i.e. maximum recursion depth exceeded.
Thanks for your help
#This is a simple timer version
from tkinter import *
window = Tk()
window.title('Tea timer')
window.minsize(300,100)
window.resizable(0,0)
class statInter(Button,Entry):
def __init__(self, posx, posy):
self.posx = posx # So the variables inside the class are defined broadly
self.posy = posy
def button(self):
Button(window).grid(row=self.posx, column=self.posy)
def field(self):
Entry(window, width=5)
sth = statInter(1,2)
sth.grid(row=1, column = 2)
window.mainloop()
Aucun commentaire:
Enregistrer un commentaire