user9437617
user9437617

Reputation:

python tkinter text 'unicode' object has no attribute 'get'

I'm trying to make a color picker with tkinter's text box but when i try to get whats in the text box I get this error 'unicode' object has no attribute 'get'

Here's my code:

def color(self): #choose a color

    def stop():# break the tkinter window
        win.destroy()

    win = Tk()
    text = Label(win, text='choose a color')
    text.grid(column=2, row=1)
    text = Label(win, text=' r     g     b ')
    text.grid(column=2, row=2)

    r = Text(win, height=1, width=3)
    r.grid(column=1, row=3)
    g = Text(win, height=1, width=3)
    g.grid(column=2, row=3)
    b = Text(win, height=1, width=3)
    b.grid(column=3, row=3)

    ok = Button(win, text='ok', command=stop)
    ok .grid(column=2, row=4)

    while True:
        r, g, b = r.get('1.0', END), g.get('1.0', END), b.get('1.0', END)
        print(r, g, b)
        win .update()

I'm on python 3 with linux if that helps.

Upvotes: 0

Views: 343

Answers (1)

Patrick Artner
Patrick Artner

Reputation: 51643

You define inputs named r,g,b - then you override them by naming the result of said Texts by its own .get()-result.

One loop later you access them again - now they are only strings and no longer have a get.

   while True:
        r, g, b = r.get('1.0', END), g.get('1.0', END), b.get('1.0', END)
        print(r, g, b)
        win .update()

Fix:

   while True:
        rr, gg, bb = r.get('1.0', END), g.get('1.0', END), b.get('1.0', END)
        print(rr, gg, bb)
        win .update()

Do you know how-to-debug-small-programs ? If not, read it. If you think you do, still read it, it is a good read.

Upvotes: 2

Related Questions