我是一名高中编程学生,我有一个小问题.我的任务是在Tkinter写一个简单的游戏,冰柱从天花板上掉下来,你必须用鼠标来避免它.很简单.但是,我遇到了一个问题.每当我在Tkinter应用程序中运行循环时,它都不会打开.我尝试使用for循环,使用time.sleep()每隔0.5秒暂停一次,循环结束后窗口就会打开.我需要做一些特殊的事情才能使循环在Tkinter中运行吗?
from Tkinter import *
import time
import random
class App:
def __init__(self, parent):
self.frame = Frame(root, bg= '#1987DF', width=800, height=800)
self.frame.bind("<Motion>", self.motionevent)
self.frame.pack()
#self.run()
def randhex(self):
b = "#"
for i in range(1, 7):
a = random.randint(0, 15)
if a == 10:
a = "A"
elif a == 11:
a = "B"
elif a == 12:
a = "C"
elif a == 13:
a = "D"
elif a == 14:
a = "E"
elif a == 15:
a = …Run Code Online (Sandbox Code Playgroud)