#! /usr/bin/python3 # =================================================================== # demonstrate graphics.py text # =================================================================== import user_interface as ui ## import graphics as gr from graphics import * # ------------------------------------------------------------------- # ---- draw text in the graphics window # ------------------------------------------------------------------- def DrawText(win,txt): if len(txt) < 1: return for s in txt: t = Text(Point(s[1],s[2]),s[0]) t.setFace('courier') t.setSize(18) t.setStyle('bold') t.setTextColor('blue') t.draw(win) return # ------------------------------------------------------------------- # ---- main # ------------------------------------------------------------------- if __name__ == '__main__': # ---- list of text strings txt = [ ('hello',500,500), ('multiple\nline',620,620), ('This is a long string',250,650) ] # ---- create graphics window win = GraphWin("Text Demo", 801, 801) win.setBackground("white") # ---- draw text DrawText(win,txt) # ---- pause ui.pause() win.close()