我是这里的新手,也是Python 3.x的新手。
我试图在tkinter中创建一个Button
或两个,当我单击第一个按钮时,例如,第三个或第四个按钮将增加和减少(使用宽度16和18)10次,然后在10次后返回为正常按钮。不使用class
。
谢谢你的帮忙
码:
from tkinter import *
import time
window1 = Tk()
window1.geometry("300x300")
btn1=Button(text="16",font=40,width=16)
btn1.pack()
# here i want to create a loop to flash the button 10 times
# i dont know wich way is better :
# to use time.sleep with for in range or use .after
# or use def with loops
#can i put line 14 and 13 together ?!
#why the first button in line 5 does not apear instantly !? why line17 affect
that so i put #?
btn1["width"]=18
btn1["text"]="18"
btn1.pack()
#time.sleep(1)
btn1["width"]=16
btn1["text"]="16"
btn1.pack()
window1.mainloop()
在这里使用:
from tkinter import *
def change(event=None):
global count
btn2['width']= 18
btn2.after(500, lambda: btn2.config(width=16))
if count< 10:
btn2.after(1000, change)
count += 1
else:
count=0
window1 = Tk()
window1.geometry("300x300")
count = 0
btn1=Button(text="btn1",font=40,width=16)
btn1.pack()
btn1.bind('<Button>', change)
btn2=Button(text="btn2",font=40,width=16)
btn2.pack()
window1.mainloop()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句