Monday 15 February 2010

python - Trying to get the value from a Tkinter scale and put it into a Label -


I have a small Python program that takes the value of a typewriter scale and puts it in a label. #! / Tuncotter import / yr / bin / python * class application: strval = StringVar () def __init __ (auto, master): frame = frame (master) frame.pack () self.slide = scale () frame, command = Self.out = label (frames, textual.lib.pn) self.slide.pack () self.out.pack () def up (self, newsletter): zodiac = Str (novel) self.stravell.set (amount) root = Tk () app = app (root) route.mainloup ()

I get more error message when I run the program: / P>

  traceback (most recent Switch to call last): File "/ Users / black / Disktop / Python / Tknetr / Skel_antry. Py", line 5, & lt; Module & gt; Class app: "/ System / Library / Firmwork / Python Framework / Version-2.5 / Lib / Python2" in the file "/ Users / Black / Desktop / Python / Tokenator / Scale_Interies", Line 7, App Strawel = Stringware () file. 5 / lib-tk / Tkinter.py ", in line 254, __init__ variable .__ init __ (self, master, value, name) file" /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2 .5 / lib-tk / Tkinter.py ", line 185, __init__ self._tk = attributeError in master.tk: 'NoneType' does not contain any attribute in the object 'tk' exception exception. Attribute Enter: "There is no attribute in the StringVar instance '_tk'" at 0x69f238 & lt; Forced method StringVar.__ del__ & lt; Tkinter.StringVar Example & gt; & Gt; Unrecognized logout   

I'm not even sure what is going wrong and I completely mess in the interface bucks. If someone tells me what I am doing I would love to.

This is because the string before you make the root principal amount is before you define the class < Code> root = Tk () , you will see how it works as expected.

However, the ideal solution will be written as you do not rely on the sequence of work, so I suggest you create a stringwire in the manufacturer:

  Class app: def __init __ (auto, master): frame = frame (master) frame.pack () self.strval = StringVar (frame) # ...    

No comments:

Post a Comment