(Python初学者,如果问题太幼稚,请原谅我)在标签下面写着“Hello”,创建一个标签或栏或任何显示我的两只乌龟的更新位置(我更新的意思是乌龟同时移动其位置变化的两个坐标) 导入Tkinter 进口龟
def run_turtles(*args):
for t, d in args:
t.circle(250, d)
root.after_idle(run_turtles, *args)
root = Tkinter.Tk()
root.withdraw()
frame = Tkinter.Frame(bg='black')
Tkinter.Label(frame, text=u'Hello', bg='grey', fg='white').pack(fill='x')
canvas = Tkinter.Canvas(frame, width=750, height=750)
canvas.pack()
frame.pack(fill='both', expand=True)
turtle1 = turtle.RawTurtle(canvas)
turtle2 = turtle.RawTurtle(canvas)
turtle1.ht(); turtle1.pu()
turtle1.left(90); turtle1.fd(250); turtle1.lt(90)
turtle1.st(); turtle1.pd()
turtle2.ht(); turtle2.pu()
turtle2.fd(250); turtle2.lt(90)
turtle2.st(); turtle2.pd()
root.deiconify()
run_turtles((turtle1, 3), (turtle2, 4))
root.mainloop()
非常感谢你!
答案 0 :(得分:0)
保存对标签的引用:turtleLabel = Tkinter.Label(frame, text=u'Hello', bg='grey', fg='white')
然后在您的run_turtles
- 函数中,您可以通过设置文本来更新标签:
turtleLabel['text'] = "Here be coordinates"
您还可以使用configure
方法更改文字:
turtleLabel.configure(text="Here be coordinates")
请注意,您无法在创建窗口小部件的同一语句中调用pack
; pack
会返回None
,这会否定尝试保存对窗口小部件的引用。