|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- from tkinter import *
- import time
- root = Tk()
- def hg():
- while cx :
- for i in range(1,5) :
- val.set(str(i)+str(i))
- root.update_idletasks()
- time.sleep(1)
- def callbegin():
- cx = True
- hg()
-
- def callover():
- cx = False
- hg()
- cx = True
- val = StringVar()
- theLabel = Label(root,textvariable = val)
- theLabel.pack()
- theButton1 = Button(root,
- text = '点我1',
- command =callbegin)
- theButton1.pack()
- theButton2 = Button(root,
- text = '点我2',
- command =callover)
- theButton2.pack(padx = 10,pady=10)
- mainloop()
复制代码
上面代码显示效果像这样
测试
点击“1”按钮,可以开始
但是无法点击“2”按钮停止程序呢
像这样类似循环,如何暂停循环或结束循环?
请大神指教一下。
def hg():
while cx :
for i in range(1,5) :
val.set(str(i)+str(i))
root.update()
time.sleep(1)
def callbegin():
global cx
cx = True
hg()
def callover():
global cx
cx = False
##hg()
|
|