Python Brackets- Need help getting a simple program to work

Hello, I am relatively new to using Brackets for python so I apologise in advance if my code is amazingly awful and unorganised.

from tkinter import *

StoryGUI=Tk()
ment=StringVar()

class StoryGUI:
def __init__(self, master):
self.master=master
master.title(“Story GUI”)

self.label=Label(master, text=“You see a dog. Do you want to pet the dog?”)
self.label.pack()

self.pet_button = Button(master, text=“Pet”, command=self.pet)
self.pet_button.pack()

self.close_button=Button(master, text=“Finish Story”, command=master.quit)
self.close_button.pack()

def pet(self):

ptext=“You pet the dog”

plabel=Label(StoryGUI, text=ptext).pack()

mlabel=Label(StoryGUI,text=“My Label”)
mbutton=Button(StoryGUI,text=“Ok”,command=mhello,fg=“red”,bg=“blue”).pack()
mEntry=Entry(StoryGUI,textvariable=ment)

root=Tk()
story_gui = StoryGUI(root)
root.mainloop()

I am trying to create a decision-making/story game and I need help organising all my buttons and making them work; I want the pet_button to print “You pet the dog” in the GUI when clicked but I can’t find any tutorials which I’m able to follow- any sort of help would be appreciated. :slight_smile:

Here’s the error message I receive:

The StoryGUI class is not an instance of the Tk class, it has a member (master) which is a Tk instance. So in the three lines (e.g. “mLabel=”), trying to use StoryGUI as a Tk isn’t going to work. I.e. the first parameter for Label() must be a Tk, which StoryGUI is not.

(For future reference: your tabs got lost when you posted your code, and I’m sure you’ve discovered by now, tabs are important in Python! The “insert code” function would preserve your tabs.)

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

1 Like