So I'm currently trying to learn python and I'm following this guide on youtube. It put me through this. But When I run it I get the error:
Traceback (most recent call last):
File "C:/Users/Frederik/Desktop/test.py", line 29
app = Application(root)
File "C:/Users/Frederik/Desktop/test.py", line 11, in __init__
self.create_widgets()
AttributeError: Application instance has no attribute 'create_widgets'
This is my code:
from Tkinter import *
class Application(Frame):
""" GUI with click counter """
def __init__(self, master):
""" Init the frame """
Frame.__init__(self,master)
self.grid()
self.button_clicks =0 #Counts the button clicks
self.create_widgets()
def create_widgets(self):
""" Create button widget """
self.button = Button(self)
self.button["text"] = "Total Clicks: 0"
self.button["command"] = self.update_count
self.button.grid()
def update_count(self):
""" Increase click count """
self.button_clicks += 1
self.button["text"] = "Total Clicks: " + str(self.button_clicks)
root = Tk()
root.title("Button Counter")
root.geometry("200x100")
app = Application(root)
root.mainloop()
def __init__by one indentation level to ensure that the method belongs to the type.defs at the same indentation level and all will be good.