gui显示字符串操作

时间:2014-02-24 14:54:37

标签: user-interface text graphics python-3.2

我正在学习Python,希望能给我的孙子们留下深刻的印象 - 希望没有人会是老一辈的!我的项目是让我在QuickBasic中编写的Hangman游戏在Windows7下工作。 我成功地准备了一个Hangedman数字和书面例程来从一个大的csv文件中提取随机单词。现在我想编写用户界面,但尝试在覆盖时返回已经使用过的位置结果 - 我无法删除现有的字符串。 以下例程是探索如何在给定位置写入字符串并将其擦除以用于游戏目的:

# attempt to write and erase text at point locations
# all works OK until returned to location already used
#
# 23 FEB 14

from graphics import *
import tkinter

def main():
# make window
win = GraphWin("Display text locator", 600, 500)
# click 1 to start    
win.getMouse()   
# establish first location
output = Text(Point(400,400),"")
output.draw(win)
# and print simulated hangman word length
output.setText("  _ _ _ _ _ _ _ _ ")
# click 2 for first string replacement
win.getMouse()
output.setText("     ABCZYX W     ")
# click 3 to blank out first string
win.getMouse()
output.setText("                   ")
# click 4 to show new string
win.getMouse()
output.setText(" and here we are again  ")
# click 5 points to new text location and display
win.getMouse()    
output = Text(Point(100,100),"")
output.draw(win)
# first string at new location
output.setText(" here's the new position ")
# click 6 to show new string
win.getMouse()
output.setText("    blank that out    ")
# click 7 to erase it
win.getMouse()
output.setText("                      ")
# click 8 points back to first location
win.getMouse()     
output = Text(Point(400,400),"")
output.draw(win)
# should blank out existing string (but fails)
output.setText("          -                 ")
# click 9 to display new string (but simply overwrites)
win.getMouse()
output.setText(" BACK TO THE FIRST POSITION ")
# click 10 exits
win.getMouse() 
win.close()

main()

感激地收到所有建议(不笑!) 非常感谢 - jeremy /

0 个答案:

没有答案