【发布时间】:2021-06-28 07:09:31
【问题描述】:
我是新来的,并且是 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 don't know which 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 appear 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()
【问题讨论】:
-
欢迎来到 SO。如果您向我们展示您到目前为止所做的事情会更好。
-
稍后使用
config()方法更新小部件的属性。