python - Not Equals to Operand not working -


i trying make when value not equals value, draw rectangle. here code.

import tkinter def a():     c1 = 1     c2 = 2     root = tkinter.tk()     canvas = tkinter.canvas(root, width=800, height=600)      def b():         if c1 != c2:             print ("test")             canvas.create_rectangle(100, 100, 500, 500, fill='blue')             root.after(10, b)     root.after(10, b) a() 

as can see, in function b, if variable c1 not equal c2 (or vice versa) should print "test". not printing, nor running draw rectangle code.

however, when place dummy print statement before ifstatement, print that.

therefore can tell not equals operand not working, can see wrong code?

you should not have root tk object inside function. i'm not sure how tkinter structured, moving root outside function idea -- additionally, need enter tkinter main loop before of after calls execute:

import tkinter root = tkinter.tk()  def a():     c1 = 1     c2 = 2      canvas = tkinter.canvas(root, width=800, height=600)     canvas.pack()      def b():         if c1 != c2:             print ("test")             canvas.create_rectangle(100, 100, 500, 500, fill='blue')             root.after(10, b)     root.after(10, b) a() root.mainloop() 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -