python - How to align the center of a textwidget in pyqtgraph -


i use textwidget display text on image, , make sure text centered in image. (i want make movie text changes every frame indicate changed).

i tried following (in jupyter notebook):

%pylab inline %gui qt import pyqtgraph pg  # new cell imv = pg.imageview() imv.show()  #new cell # add textwidget tw_center = pg.textitem('') tw_center.setfont(pg.qt.qtgui.qfont("arial", 20)) imv.additem(tw_center) # set in center tw_center.setpos(50, 0) # display text in red make visible tw_center.settext('hi there', (255,0,0))  # create , show data data = np.random.rand(100,100) imv.setimage(data) 

however, results in non-centered text label left corner in center. how center of text in center of image? size of data might change, text in textwidget, i'm looking more clever way trial , error. looked @ setanchor method specifies corners.

regards, dirk

it looks need set anchor right. if @ documentation, can see initiate textitem different anchor. centered, might need like

tw_center = pg.textitem('',anchor=(0.5,0)) 

this set item's anchor centered in x-direction.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -