我的目标是打开图像一定时间,然后再显示另一个随机图像。
Windows将每个图像作为新实例打开,因此我想在打开新图像之前关闭旧图像。
自动执行此操作的绝对最简单的方法是什么。除了不关闭旧图像这一件事之外,简单的程序几乎可以按预期工作。
cont = True
#### Time Functions
def waits(): # basic wait
time.sleep(s)
def waitm(): # basic wait
time.sleep(s)
def waitl(): # basic wait
time.sleep(s)
def wait(): # wait between notes
time.sleep(wt)
g3 = Image.open(imd+"g3.png")
a3 = Image.open(imd+"a3.png")
b3 = Image.open(imd+"b3.png")
c4 = Image.open(imd+"c4.png")
d4 = Image.open(imd+"d4.png")
e4 = Image.open(imd+"e4.png")
f4s = Image.open(imd+"f4s.png")
g4 = Image.open(imd+"g4.png")
def randomNotes():
GM_s_o = (g3, a3, b3, c4, d4, e4, f4s, g4) # G-major scale, open string # f
r_note = random.choice(GM_s_o)
r_note.show()
waits()
def waitTime():
global wt
print("Choose wait time.")
answer = input("s for short, m for medium, l for long.")
if answer == "s":
wt = 3
return wt
if answer == "m":
wt = 6
return wt
if answer == "l":
wt = 10
return wt
else:
waitTime()
def program():
global cont
if cont == True:
randomNotes()
randomNotes()
randomNotes()
randomNotes()
randomNotes()
randomNotes()
randomNotes()
print("Would you like to continue?")
answer = input("y for yes, n for no.")
if answer == "y":
cont = True
program()
if answer == "n":
cont = False
if cont == False:
exit()
#### Actual
waitTime()
program()