user2321092
user2321092

Reputation: 11

Python - Tkinter - GUI

I'm creating a new application for my current project using Python. This is the first time I use it and it has been a learning experience...

I have a button in my application that calls the askcolor() function from Python. Everything works fine the first time but after that, it gives me the following error.

AttributeError: 'str' object has no attribute 'set'

This is the sequence that I have working in my application:

  1. The user click on the Select Color button:

    self.bc_bttn=Button(self, text='Select Color', command=lambda: self.callback())
    
  2. The function calls the callback function and I select the proper color

    def callback(self):
         (triple, hexstr) = askcolor()
         if triple:
             triple_string = str(triple)
             triple_string2 = re.findall('[0-9, ]',triple_string);
             triple_bkgColor = ''.join(triple_string2)
             print triple_bkgColor
             self.overlayColorValue.set(triple_bkgColor)
    
  3. self.overlayColorValue.set(triple_bkgColor) changes the value of the text field entry so the user will see the correct value on the application

  4. I press the Save button

    self.overlayColorValue = self.bc_ent.get()
    body.set('overlay-color', self.overlayColorValue)
    
  5. My changes are written to the xml file

    tree.write(CONFIG_XML)
    
  6. Everything works fine this time but if I want to do the same thing again to change the color. then I have the following error when I click on the Select Color button

    AttributeError: 'str' object has no attribute 'set'
    

Upvotes: 1

Views: 666

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121486

You replaced your self.overlayColorValue attribute with the return value of self.bc_ent.get(), which is a str.

Presumably, before that time, it was a label, and you wanted to call .set() on it instead:

self.overlayColorValue.set(self.bc_ent.get())
body.set('overlay-color', self.overlayColorValue.get())

Upvotes: 1

Related Questions