-2

I am using Wing to write and debug a Tkinter GUI. I am finding that the Stack Data View doesn't seem to match the actual attributes of my widgets. Take this code for example:

import Tkinter
import ttk

root = Tkinter.Tk()
checkbutton = ttk.Checkbutton(root, text="Test Check Button")
print checkbutton.text

This gives me an attribute error at the last line. However, when I look at the stack, there is clearly an attribute called 'text' with the value that I'm looking for:

Wing screen capture

Anyone know what's going on?

I'm using:

  • Wing version: Wing IDE Pro 5.1.3-1 (rev 33002)
  • Tkinter version: '$Revision: 81008 $'
  • Python version: 2.7.10
Emma
  • 1,287
  • 2
  • 17
  • 22

2 Answers2

3

I posted this to the Wing email list, and I got the following response from the developers:

It looks like a ttk.Checkbutton defines keys() and __getitem__() methods to exposes tk attributes via checkbutton[<name>]. Because of the keys() and __getitem__(), Wing is displaying the instance as if it were a dictionary, with the keys and values interspersed with the attributes. Wing does this because often you want to view an object that defines keys() and __getitem__() as if it were a dictionary, but I agree that it's confusing in this instance.

We'll try to improve this in a future release.

Emma
  • 1,287
  • 2
  • 17
  • 22
1

What you are calling attributes are not object attributes. Widgets use an internal system for managing the widget options. .text is not an attribute, which is why you get the error. To reference the configuration use .cget(...) to get the value and .configure(...) to change the value.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • That's true, but I'm not so much confused about the attribute error as I am about the presence of a .text attribute in the stack data. Why is Wing showing me an attribute that doesn't actually exist? – Emma Aug 19 '15 at 20:38
  • @Emma I think that at least logically (from an OO point of view) `text` is considered an attribute, and that's probably why Wing developers decided to include it as an attribute. – nbro Aug 19 '15 at 20:46