python图像技术处理倒计时_Python-Tkinter画布中的倒数计时器

您好,我想在子例程中创建一个倒数计时器,然后将其显示在画布上.我不完全确定从哪里开始,我已经对其进行了一些研究,并能够使用time.sleep(x)函数创建一个函数,但是该方法冻结了整个程序,这不是我想要的.我还查询了有关计时器的其他问题,并尝试将其合并到我的程序中,但是我还没有成功.

TLDR;我想创建一个倒计时计时器,该计时器从60秒开始倒计时并显示在画布上,然后在计时器达到0时让它执行某些操作.

有谁能指出我正确的方向?

提前致谢.

编辑:根据提供的建议,我尝试将它们放入程序时没有多大运气.

不知道此代码中是否存在重大错误,还是仅仅是简单的错误.

我在运行它时遇到的错误在代码下方.

这是我想要计时器的代码的一部分:

def main(): #First thing that loads when the program is executed.

global window

global tkinter

global canvas

global cdtimer

window = Tk()

cdtimer = 60

window.title("JailBreak Bob")

canvas = Canvas(width = 960, height = 540, bg = "white")

photo = PhotoImage(file="main.gif")

canvas.bind("", buttonclick_mainscreen)

canvas.pack(expand = YES, fill = BOTH)

canvas.create_image(1, 1, image = photo, anchor = NW)

window.mainloop()

def buttonclick_mainscreen(event):

pressed = ""

if event.x >18 and event.x <365 and event.y > 359 and event.y < 417 : pressed = 1

if event.x >18 and event.x <365 and event.y > 421 and event.y < 473 : pressed = 2

if event.x >18 and event.x <365 and event.y > 477 and event.y < 517 : pressed = 3

if pressed == 1 :

gamescreen()

if pressed == 2 :

helpscreen()

if pressed == 3 :

window.destroy()

def gamescreen():

photo = PhotoImage(file="gamescreen.gif")

canvas.bind("", buttonclick_gamescreen)

canvas.pack(expand = YES, fill = BOTH)

canvas.create_image(1, 1, image = photo, anchor = NW)

game1 = PhotoImage(file="1.gif")

canvas.create_image(30, 65, image = game1, anchor = NW)

e1 = Entry(canvas, width = 11)

e2 = Entry(canvas, width = 11)

canvas.create_window(390, 501, window=e1, anchor = NW)

canvas.create_window(551, 501, window=e2, anchor = NW)

canvas.after(1, gamescreen)

window.mainloop()

def cdtimer():

canvas.delete(ALL)

global cdtimer

cdtimer -= 1

canvas.create_text(510, 6, text=cdtimer, font="Ubuntu 29 bold", anchor = NW)

if cdtimer == 0:

scorescreen()

else:

canvas.after(1000, gamescreen)

main()

错误MSG:

Exception in Tkinter callback

Traceback (most recent call last):

File "/usr/lib/python3.2/tkinter/__init__.py", line 1402, in __call__

return self.func(*args)

File "/usr/lib/python3.2/tkinter/__init__.py", line 490, in callit

func(*args)

File "/home/ppppwn3d/workspace/Python/JailBreakBob/JailBreakBob.py", line 50, in gamescreen

e1 = Entry(canvas, width = 11)

File "/usr/lib/python3.2/tkinter/__init__.py", line 2372, in __init__

Widget.__init__(self, master, 'entry', cnf, kw)

File "/usr/lib/python3.2/tkinter/__init__.py", line 1952, in __init__

cnf = _cnfmerge((cnf, kw))

File "/usr/lib/python3.2/tkinter/__init__.py", line 71, in _cnfmerge

if isinstance(cnfs, dict):

RuntimeError: maximum recursion depth exceeded while calling a Python object

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值