简体   繁体   中英

How do I display a variable in a Zelle graphics window?

I have some int variables that I need to display into a Zelle graphics window in Python. I'm trying to do this with a GraphWin() window but I have not found a way. How can I take my integers and display them in a window.

You can display an int in Zelle graphics by passing it as the text argument to a Text object, along with where you want it placed. You can also select the characteristics of the font:

from graphics import *

win = GraphWin("My Number")

number = 1729

text_1 = Text(Point(100, 100), number)
text_1.setFace('arial')
text_1.setSize(18)
text_1.setStyle('bold')
text_1.setTextColor('red')

text_1.draw(win)

win.getMouse()  # pause for click in window
win.close()

You don't need to convert the number to a str first, the Text object appears to handle that for you.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM