0
ボールを画面の片側に移動して戻ってきて、戻ってくるようにしようとしています。このプログラムを実行しようとすると、tkinterウィンドウは表示されませんが、スリープ(0.5)の部分を取り除くと、ボールがすでに画面から外れているときに表示されます。誰かが私が何をやったのか教えてくれますか?sleep()の部分を追加するとtkinterのウィンドウが開かない
from tkinter import *
from time import sleep
window = Tk()
cWidth = 800
cHeight = 500
c = Canvas(window, width = cWidth, height = cHeight, bg='black')
c.pack()
x = 400
y = 250
ball = c.create_polygon(x, y, x, y+25, x+25, y+25, x+25,y, fill='yellow')
Ball_move = 10
for i in range(200):
c.move(ball, Ball_move, 0)
window.update
x += Ball_move
if x == cWidth:
Ball_move = -Ball_move
sleep(0.5)
window.mainloop()
http://stackoverflow.com/questions/10393886/python-time-sleepこれを確認してください。 – Lafexlos
関連するhttp://stackoverflow.com/questions/30284270/why-does-time-sleep-pause-tkinter-window-before-it-opensおよびhttp://stackoverflow.com/questions/33175457/time-sleep -equivalent-on-tkinter –
私は 'window.update'(括弧なし)の代わりに' window.update() 'をリングに入れます;-)、' timeを使用しないことに関する他のヒントに加えて。睡眠(...) 'tkinterのイベントループで... – Dilettant