Code Returns Error?(Python) itemconfigure is not defined?












-1














Hello I am making a timer. Here is my code:



from tkinter import*
import time
Screen=Tk()
Screen.resizable(0,0)
myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
myText.pack()
aText=Label(Screen,text="0:0",font=(None,30))
aText.pack()
def start_timer():
x=1
while(True):
time.sleep(1)
x=x+1
itemconfigure(aText,text=x)
strBTN=Button(Screen,text="Start",bg="purple",font=
("Helvetica",45),command=start_timer)
strBTN.pack()
Screen.mainloop()


But on line 14 is says: Error:itemconfigure is not defined. Please help!










share|improve this question





























    -1














    Hello I am making a timer. Here is my code:



    from tkinter import*
    import time
    Screen=Tk()
    Screen.resizable(0,0)
    myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
    myText.pack()
    aText=Label(Screen,text="0:0",font=(None,30))
    aText.pack()
    def start_timer():
    x=1
    while(True):
    time.sleep(1)
    x=x+1
    itemconfigure(aText,text=x)
    strBTN=Button(Screen,text="Start",bg="purple",font=
    ("Helvetica",45),command=start_timer)
    strBTN.pack()
    Screen.mainloop()


    But on line 14 is says: Error:itemconfigure is not defined. Please help!










    share|improve this question



























      -1












      -1








      -1







      Hello I am making a timer. Here is my code:



      from tkinter import*
      import time
      Screen=Tk()
      Screen.resizable(0,0)
      myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
      myText.pack()
      aText=Label(Screen,text="0:0",font=(None,30))
      aText.pack()
      def start_timer():
      x=1
      while(True):
      time.sleep(1)
      x=x+1
      itemconfigure(aText,text=x)
      strBTN=Button(Screen,text="Start",bg="purple",font=
      ("Helvetica",45),command=start_timer)
      strBTN.pack()
      Screen.mainloop()


      But on line 14 is says: Error:itemconfigure is not defined. Please help!










      share|improve this question















      Hello I am making a timer. Here is my code:



      from tkinter import*
      import time
      Screen=Tk()
      Screen.resizable(0,0)
      myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
      myText.pack()
      aText=Label(Screen,text="0:0",font=(None,30))
      aText.pack()
      def start_timer():
      x=1
      while(True):
      time.sleep(1)
      x=x+1
      itemconfigure(aText,text=x)
      strBTN=Button(Screen,text="Start",bg="purple",font=
      ("Helvetica",45),command=start_timer)
      strBTN.pack()
      Screen.mainloop()


      But on line 14 is says: Error:itemconfigure is not defined. Please help!







      python python-3.x






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 23:03

























      asked Nov 11 at 16:50







      user10636857































          2 Answers
          2






          active

          oldest

          votes


















          2














          It's unclear exactly what it is you're trying to do, but your start_timer function is an infinite busy loop that will hang your GUI, so I assume that's not it! Maybe you meant to call Tk.after?



          def start_timer(x=0):
          x+=1
          Screen.after(1000, lambda x=x: start_timer(x))
          # 1000 is the time (in milliseconds) before the callback should be invoked again
          # lambda x=x... is the callback itself. It binds start_timer's x to the scope of
          # the lambda, then calls start_timer with that x.
          itemconfigure(aText,text=x)


          I'm going out on a limb and say that you expect itemconfigure(aText, text=x) to change the text on the label? You should instead be using:



              ...
          aText.config(text=x)





          share|improve this answer





















          • Note that even after you do this, you may not get the behavior you expect. Try pressing "start" more than once.
            – Adam Smith
            Nov 11 at 18:19










          • why did you delete my while loop,and why did you delete that the value of x increases every second? Those are important for timers
            – user10636857
            Nov 11 at 18:25










          • @KitKatFam because your loop doesn't work. That was explained in the first sentence.
            – Nick A
            Nov 11 at 18:25












          • @KitKatFam the while True loop is what was locking up your code. I re-implemented it in a way that actually works (note that x is still incremented every call)
            – Adam Smith
            Nov 11 at 18:26










          • @KitKatFam note also that I explained that in my answer: "your start_timer function is an infinite busy loop that will hang your GUI"
            – Adam Smith
            Nov 11 at 18:27



















          0














          To change the text of a Label you have to use Label's method config(). So, instead of itemconfigure(aText,text=x), do aText.config(text=x). I think itemconfigure() function doesn't exist.



          Also, there are other problems. For example, if you define a function with an infinite loop as a button callback, the button will always remain pressed (buttons remain pressed till the callback finishes). That's why I recommend you to use Screen's method after() at the end of the callback, and make it execute the same function.
          after() executes a function after the number of milliseconds entered, so Screen.after(1000, function) will pause the execution during a second and execute the function.
          Also you can use s variable to store the seconds. When s equals 60, it resets to 0 and increases in 1 the number of minutes (m).
          Here you have the code:



          from tkinter import*

          Screen=Tk()
          Screen.resizable(0,0)

          myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
          myText.pack()

          aText=Label(Screen,text="0:0",font=(None,30))
          aText.pack()

          def start_timer():
          global s, m, aText, Screen
          aText.config(text = str(m) + ":" + str(s))
          s += 1
          if s == 60:
          s = 0
          m += 1
          Screen.after(1000,start_timer)

          s = 0
          m = 0

          strBTN=Button(Screen,text="Start",bg="purple",font=("Helvetica",45),command=start_timer)
          strBTN.pack()

          Screen.mainloop()


          This one should work (in my computer it works properly). If you don't understand something just ask it.






          share|improve this answer























          • dosent work,when i run it and you click the button,it freezes and report problem to microsoft..
            – user10636857
            Nov 11 at 17:40










          • @KitKatFam That's a different problem, that's because you have an infinite loop in your code
            – Nick A
            Nov 11 at 18:13










          • Now it works. Try it
            – ARD
            Nov 11 at 18:51











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250982%2fcode-returns-errorpython-itemconfigure-is-not-defined%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown
























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          It's unclear exactly what it is you're trying to do, but your start_timer function is an infinite busy loop that will hang your GUI, so I assume that's not it! Maybe you meant to call Tk.after?



          def start_timer(x=0):
          x+=1
          Screen.after(1000, lambda x=x: start_timer(x))
          # 1000 is the time (in milliseconds) before the callback should be invoked again
          # lambda x=x... is the callback itself. It binds start_timer's x to the scope of
          # the lambda, then calls start_timer with that x.
          itemconfigure(aText,text=x)


          I'm going out on a limb and say that you expect itemconfigure(aText, text=x) to change the text on the label? You should instead be using:



              ...
          aText.config(text=x)





          share|improve this answer





















          • Note that even after you do this, you may not get the behavior you expect. Try pressing "start" more than once.
            – Adam Smith
            Nov 11 at 18:19










          • why did you delete my while loop,and why did you delete that the value of x increases every second? Those are important for timers
            – user10636857
            Nov 11 at 18:25










          • @KitKatFam because your loop doesn't work. That was explained in the first sentence.
            – Nick A
            Nov 11 at 18:25












          • @KitKatFam the while True loop is what was locking up your code. I re-implemented it in a way that actually works (note that x is still incremented every call)
            – Adam Smith
            Nov 11 at 18:26










          • @KitKatFam note also that I explained that in my answer: "your start_timer function is an infinite busy loop that will hang your GUI"
            – Adam Smith
            Nov 11 at 18:27
















          2














          It's unclear exactly what it is you're trying to do, but your start_timer function is an infinite busy loop that will hang your GUI, so I assume that's not it! Maybe you meant to call Tk.after?



          def start_timer(x=0):
          x+=1
          Screen.after(1000, lambda x=x: start_timer(x))
          # 1000 is the time (in milliseconds) before the callback should be invoked again
          # lambda x=x... is the callback itself. It binds start_timer's x to the scope of
          # the lambda, then calls start_timer with that x.
          itemconfigure(aText,text=x)


          I'm going out on a limb and say that you expect itemconfigure(aText, text=x) to change the text on the label? You should instead be using:



              ...
          aText.config(text=x)





          share|improve this answer





















          • Note that even after you do this, you may not get the behavior you expect. Try pressing "start" more than once.
            – Adam Smith
            Nov 11 at 18:19










          • why did you delete my while loop,and why did you delete that the value of x increases every second? Those are important for timers
            – user10636857
            Nov 11 at 18:25










          • @KitKatFam because your loop doesn't work. That was explained in the first sentence.
            – Nick A
            Nov 11 at 18:25












          • @KitKatFam the while True loop is what was locking up your code. I re-implemented it in a way that actually works (note that x is still incremented every call)
            – Adam Smith
            Nov 11 at 18:26










          • @KitKatFam note also that I explained that in my answer: "your start_timer function is an infinite busy loop that will hang your GUI"
            – Adam Smith
            Nov 11 at 18:27














          2












          2








          2






          It's unclear exactly what it is you're trying to do, but your start_timer function is an infinite busy loop that will hang your GUI, so I assume that's not it! Maybe you meant to call Tk.after?



          def start_timer(x=0):
          x+=1
          Screen.after(1000, lambda x=x: start_timer(x))
          # 1000 is the time (in milliseconds) before the callback should be invoked again
          # lambda x=x... is the callback itself. It binds start_timer's x to the scope of
          # the lambda, then calls start_timer with that x.
          itemconfigure(aText,text=x)


          I'm going out on a limb and say that you expect itemconfigure(aText, text=x) to change the text on the label? You should instead be using:



              ...
          aText.config(text=x)





          share|improve this answer












          It's unclear exactly what it is you're trying to do, but your start_timer function is an infinite busy loop that will hang your GUI, so I assume that's not it! Maybe you meant to call Tk.after?



          def start_timer(x=0):
          x+=1
          Screen.after(1000, lambda x=x: start_timer(x))
          # 1000 is the time (in milliseconds) before the callback should be invoked again
          # lambda x=x... is the callback itself. It binds start_timer's x to the scope of
          # the lambda, then calls start_timer with that x.
          itemconfigure(aText,text=x)


          I'm going out on a limb and say that you expect itemconfigure(aText, text=x) to change the text on the label? You should instead be using:



              ...
          aText.config(text=x)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 18:14









          Adam Smith

          33.2k53174




          33.2k53174












          • Note that even after you do this, you may not get the behavior you expect. Try pressing "start" more than once.
            – Adam Smith
            Nov 11 at 18:19










          • why did you delete my while loop,and why did you delete that the value of x increases every second? Those are important for timers
            – user10636857
            Nov 11 at 18:25










          • @KitKatFam because your loop doesn't work. That was explained in the first sentence.
            – Nick A
            Nov 11 at 18:25












          • @KitKatFam the while True loop is what was locking up your code. I re-implemented it in a way that actually works (note that x is still incremented every call)
            – Adam Smith
            Nov 11 at 18:26










          • @KitKatFam note also that I explained that in my answer: "your start_timer function is an infinite busy loop that will hang your GUI"
            – Adam Smith
            Nov 11 at 18:27


















          • Note that even after you do this, you may not get the behavior you expect. Try pressing "start" more than once.
            – Adam Smith
            Nov 11 at 18:19










          • why did you delete my while loop,and why did you delete that the value of x increases every second? Those are important for timers
            – user10636857
            Nov 11 at 18:25










          • @KitKatFam because your loop doesn't work. That was explained in the first sentence.
            – Nick A
            Nov 11 at 18:25












          • @KitKatFam the while True loop is what was locking up your code. I re-implemented it in a way that actually works (note that x is still incremented every call)
            – Adam Smith
            Nov 11 at 18:26










          • @KitKatFam note also that I explained that in my answer: "your start_timer function is an infinite busy loop that will hang your GUI"
            – Adam Smith
            Nov 11 at 18:27
















          Note that even after you do this, you may not get the behavior you expect. Try pressing "start" more than once.
          – Adam Smith
          Nov 11 at 18:19




          Note that even after you do this, you may not get the behavior you expect. Try pressing "start" more than once.
          – Adam Smith
          Nov 11 at 18:19












          why did you delete my while loop,and why did you delete that the value of x increases every second? Those are important for timers
          – user10636857
          Nov 11 at 18:25




          why did you delete my while loop,and why did you delete that the value of x increases every second? Those are important for timers
          – user10636857
          Nov 11 at 18:25












          @KitKatFam because your loop doesn't work. That was explained in the first sentence.
          – Nick A
          Nov 11 at 18:25






          @KitKatFam because your loop doesn't work. That was explained in the first sentence.
          – Nick A
          Nov 11 at 18:25














          @KitKatFam the while True loop is what was locking up your code. I re-implemented it in a way that actually works (note that x is still incremented every call)
          – Adam Smith
          Nov 11 at 18:26




          @KitKatFam the while True loop is what was locking up your code. I re-implemented it in a way that actually works (note that x is still incremented every call)
          – Adam Smith
          Nov 11 at 18:26












          @KitKatFam note also that I explained that in my answer: "your start_timer function is an infinite busy loop that will hang your GUI"
          – Adam Smith
          Nov 11 at 18:27




          @KitKatFam note also that I explained that in my answer: "your start_timer function is an infinite busy loop that will hang your GUI"
          – Adam Smith
          Nov 11 at 18:27













          0














          To change the text of a Label you have to use Label's method config(). So, instead of itemconfigure(aText,text=x), do aText.config(text=x). I think itemconfigure() function doesn't exist.



          Also, there are other problems. For example, if you define a function with an infinite loop as a button callback, the button will always remain pressed (buttons remain pressed till the callback finishes). That's why I recommend you to use Screen's method after() at the end of the callback, and make it execute the same function.
          after() executes a function after the number of milliseconds entered, so Screen.after(1000, function) will pause the execution during a second and execute the function.
          Also you can use s variable to store the seconds. When s equals 60, it resets to 0 and increases in 1 the number of minutes (m).
          Here you have the code:



          from tkinter import*

          Screen=Tk()
          Screen.resizable(0,0)

          myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
          myText.pack()

          aText=Label(Screen,text="0:0",font=(None,30))
          aText.pack()

          def start_timer():
          global s, m, aText, Screen
          aText.config(text = str(m) + ":" + str(s))
          s += 1
          if s == 60:
          s = 0
          m += 1
          Screen.after(1000,start_timer)

          s = 0
          m = 0

          strBTN=Button(Screen,text="Start",bg="purple",font=("Helvetica",45),command=start_timer)
          strBTN.pack()

          Screen.mainloop()


          This one should work (in my computer it works properly). If you don't understand something just ask it.






          share|improve this answer























          • dosent work,when i run it and you click the button,it freezes and report problem to microsoft..
            – user10636857
            Nov 11 at 17:40










          • @KitKatFam That's a different problem, that's because you have an infinite loop in your code
            – Nick A
            Nov 11 at 18:13










          • Now it works. Try it
            – ARD
            Nov 11 at 18:51
















          0














          To change the text of a Label you have to use Label's method config(). So, instead of itemconfigure(aText,text=x), do aText.config(text=x). I think itemconfigure() function doesn't exist.



          Also, there are other problems. For example, if you define a function with an infinite loop as a button callback, the button will always remain pressed (buttons remain pressed till the callback finishes). That's why I recommend you to use Screen's method after() at the end of the callback, and make it execute the same function.
          after() executes a function after the number of milliseconds entered, so Screen.after(1000, function) will pause the execution during a second and execute the function.
          Also you can use s variable to store the seconds. When s equals 60, it resets to 0 and increases in 1 the number of minutes (m).
          Here you have the code:



          from tkinter import*

          Screen=Tk()
          Screen.resizable(0,0)

          myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
          myText.pack()

          aText=Label(Screen,text="0:0",font=(None,30))
          aText.pack()

          def start_timer():
          global s, m, aText, Screen
          aText.config(text = str(m) + ":" + str(s))
          s += 1
          if s == 60:
          s = 0
          m += 1
          Screen.after(1000,start_timer)

          s = 0
          m = 0

          strBTN=Button(Screen,text="Start",bg="purple",font=("Helvetica",45),command=start_timer)
          strBTN.pack()

          Screen.mainloop()


          This one should work (in my computer it works properly). If you don't understand something just ask it.






          share|improve this answer























          • dosent work,when i run it and you click the button,it freezes and report problem to microsoft..
            – user10636857
            Nov 11 at 17:40










          • @KitKatFam That's a different problem, that's because you have an infinite loop in your code
            – Nick A
            Nov 11 at 18:13










          • Now it works. Try it
            – ARD
            Nov 11 at 18:51














          0












          0








          0






          To change the text of a Label you have to use Label's method config(). So, instead of itemconfigure(aText,text=x), do aText.config(text=x). I think itemconfigure() function doesn't exist.



          Also, there are other problems. For example, if you define a function with an infinite loop as a button callback, the button will always remain pressed (buttons remain pressed till the callback finishes). That's why I recommend you to use Screen's method after() at the end of the callback, and make it execute the same function.
          after() executes a function after the number of milliseconds entered, so Screen.after(1000, function) will pause the execution during a second and execute the function.
          Also you can use s variable to store the seconds. When s equals 60, it resets to 0 and increases in 1 the number of minutes (m).
          Here you have the code:



          from tkinter import*

          Screen=Tk()
          Screen.resizable(0,0)

          myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
          myText.pack()

          aText=Label(Screen,text="0:0",font=(None,30))
          aText.pack()

          def start_timer():
          global s, m, aText, Screen
          aText.config(text = str(m) + ":" + str(s))
          s += 1
          if s == 60:
          s = 0
          m += 1
          Screen.after(1000,start_timer)

          s = 0
          m = 0

          strBTN=Button(Screen,text="Start",bg="purple",font=("Helvetica",45),command=start_timer)
          strBTN.pack()

          Screen.mainloop()


          This one should work (in my computer it works properly). If you don't understand something just ask it.






          share|improve this answer














          To change the text of a Label you have to use Label's method config(). So, instead of itemconfigure(aText,text=x), do aText.config(text=x). I think itemconfigure() function doesn't exist.



          Also, there are other problems. For example, if you define a function with an infinite loop as a button callback, the button will always remain pressed (buttons remain pressed till the callback finishes). That's why I recommend you to use Screen's method after() at the end of the callback, and make it execute the same function.
          after() executes a function after the number of milliseconds entered, so Screen.after(1000, function) will pause the execution during a second and execute the function.
          Also you can use s variable to store the seconds. When s equals 60, it resets to 0 and increases in 1 the number of minutes (m).
          Here you have the code:



          from tkinter import*

          Screen=Tk()
          Screen.resizable(0,0)

          myText=Label(Screen,text="Welcome To X Timer!",font=(None,50),bg="green")
          myText.pack()

          aText=Label(Screen,text="0:0",font=(None,30))
          aText.pack()

          def start_timer():
          global s, m, aText, Screen
          aText.config(text = str(m) + ":" + str(s))
          s += 1
          if s == 60:
          s = 0
          m += 1
          Screen.after(1000,start_timer)

          s = 0
          m = 0

          strBTN=Button(Screen,text="Start",bg="purple",font=("Helvetica",45),command=start_timer)
          strBTN.pack()

          Screen.mainloop()


          This one should work (in my computer it works properly). If you don't understand something just ask it.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 18:41

























          answered Nov 11 at 17:31









          ARD

          83




          83












          • dosent work,when i run it and you click the button,it freezes and report problem to microsoft..
            – user10636857
            Nov 11 at 17:40










          • @KitKatFam That's a different problem, that's because you have an infinite loop in your code
            – Nick A
            Nov 11 at 18:13










          • Now it works. Try it
            – ARD
            Nov 11 at 18:51


















          • dosent work,when i run it and you click the button,it freezes and report problem to microsoft..
            – user10636857
            Nov 11 at 17:40










          • @KitKatFam That's a different problem, that's because you have an infinite loop in your code
            – Nick A
            Nov 11 at 18:13










          • Now it works. Try it
            – ARD
            Nov 11 at 18:51
















          dosent work,when i run it and you click the button,it freezes and report problem to microsoft..
          – user10636857
          Nov 11 at 17:40




          dosent work,when i run it and you click the button,it freezes and report problem to microsoft..
          – user10636857
          Nov 11 at 17:40












          @KitKatFam That's a different problem, that's because you have an infinite loop in your code
          – Nick A
          Nov 11 at 18:13




          @KitKatFam That's a different problem, that's because you have an infinite loop in your code
          – Nick A
          Nov 11 at 18:13












          Now it works. Try it
          – ARD
          Nov 11 at 18:51




          Now it works. Try it
          – ARD
          Nov 11 at 18:51


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250982%2fcode-returns-errorpython-itemconfigure-is-not-defined%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          Bicuculline

          さくらももこ