Getting tkinter StringVar() error on init

Getting tkinter StringVar() error on init

Asked on November 27, 2018 in tkinter.
Add Comment


  • 3 Answer(s)

    You can try this answer:

        The StringVar needs a master:

    >>> root = Tk()
    >>> StringVar()
    <Tkinter.StringVar instance at 0x0000000004435508>
    

    Actually this works  when Tk a new interpreter is created.

    >>> from Tkinter import *
    >>> StringVar()
    Traceback (most recent call last):
        File "<input>", line 1, in <module>
        File "C:\Python26\lib\lib-tk\Tkinter.py", line 251, in __init__
            Variable.__init__(self, master, value, name)
        File "C:\Python26\lib\lib-tk\Tkinter.py", line 182, in __init__
            self._tk = master.tk
    AttributeError: 'NoneType' object has no attribute 'tk'
    >>> root = Tk()
    >>> StringVar()
    <Tkinter.StringVar instance at 0x00000000044C4408>
    

    Here the issue with this instance we could find the literature they show only partial snippets that are supposed to be inside a class or in a longer program so that imports and other code are not explicitly indicated.

     

    Answered on November 27, 2018.
    Add Comment

    StringVar needs a master:

    >>> StringVar(Tk())
    <Tkinter.StringVar instance at 0x0000000004435208>
    >>> 

    or more commonly:

    >>> root = Tk()
    >>> StringVar()
    <Tkinter.StringVar instance at 0x0000000004435508>

    When you instantiate Tk a new interpreter is created. Before that nothing works:

    >>> from Tkinter import *
    >>> StringVar()
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
      File "C:\Python26\lib\lib-tk\Tkinter.py", line 251, in __init__
        Variable.__init__(self, master, value, name)
      File "C:\Python26\lib\lib-tk\Tkinter.py", line 182, in __init__
        self._tk = master.tk
    AttributeError: 'NoneType' object has no attribute 'tk'
    >>> root = Tk()
    >>> StringVar()
    <Tkinter.StringVar instance at 0x00000000044C4408>
    Answered on February 25, 2019.
    Add Comment

    (Python version: 3.1.1)

    I am having a strange problem with StringVar in tkinter. While attempting to continuously keep a Message widget updated in a project, I kept getting an error while trying to create the variable. I jumped out to an interactive python shell to investigate and this is what I got:

    >>> StringVar
    <class 'tkinter.StringVar'>
    >>> StringVar()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python31\lib\tkinter\__init__.py", line 243, in __init__
        Variable.__init__(self, master, value, name)
      File "C:\Python31\lib\tkinter\__init__.py", line 174, in __init__
        self._tk = master.tk
    AttributeError: 'NoneType' object has no attribute 'tk'
    >>>
    Answered on April 17, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.