0

(Python 初心者の方、質問が幼稚すぎたらすみません) 「こんにちは」というラベルの下に、ラベルやバーなどを作成して、2 つのタートルの更新位置を表示します (更新とは、タートルが移動するとその位置の 2 つの座標が同時に変化します) import Tkinter import turtle

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()

本当にありがとう!!

4

1 に答える 1

0

Label への参照を保存します。turtleLabel = Tkinter.Label(frame, text=u'Hello', bg='grey', fg='white')

そして、あなたのrun_turtles-function で、そのテキストを設定することでラベルを更新できます:

turtleLabel['text'] = "Here be coordinates"

configureメソッドを使用してテキストを変更することもできます。

turtleLabel.configure(text="Here be coordinates")

packウィジェットを作成するのと同じステートメントで呼び出すことはできないことに注意してください。これは、ウィジェットへの参照を保存しようとすることを否定しますpackNone

于 2013-01-27T16:23:27.767 に答える