Hey, when I execute the following code I get "App instance has no attribute rolls" I have no clue as to why this is and any help would be awesome, Thanks.

import Tkinter

class App:

    def __init__(self, master):
        self.sticky_all = Tkinter.N+Tkinter.W+Tkinter.E+Tkinter.S
        self.frame = Tkinter.Frame(master)
        self.frame.pack()

        # Dice Buttons.
        self.bd4 = Tkinter.Button(self.frame, text="D4", command = self.roll_dice()) # Button for D4.

        # Text Field.
        self.rolls = Tkinter.Text(self.frame, width=15, height=1)
        self.rolls.tag_configure("center", justify='center')

        # Grid.
        self.rolls.grid(row=0, column=1)
        self.bd4.grid(row=0, column=0)

    def roll_dice(self):
        self.rolls.insert('end', 'text', 'center')

root = Tkinter.Tk()
app = App(root)
root.mainloop()

Recommended Answers

All 2 Replies

Ah, okay.
I was sending the Result of the function, not the actual function itself.
To fix this I used lambda between the = and my function.
eg.

self.bd4 = Tkinter.Button(self.frame, text="D4", command = lambda: self.roll_dice())

Since you are not passing any args, this will do:
self.bd4 = Tkinter.Button(self.frame, text="D4", command=self.roll_dice)

also
self.sticky_all = 'ewns'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.