from tkinter import *
a=Tk()
a.geometry('300x300')
x=0
y=True
z=1
def f():
global y
y=True
a.after(200,ks)
def ks():
global x,y,z
if 0<=x<270:
if y==True:
if z==1:
x+=10
L4.place(x=x,y=20)
elif z==0:
x-=10
L4.place(x=x,y=20)
a.after(200,ks)
else:
x=x
elif x>=270:
z=0
x-=10
L4.place(x=x,y=20)
a.after(200,ks)
elif x<0:
z=1
x=x+10
L4.place(x=x,y=20)
a.after(200,ks)
def tz():
global y
y=False
a.after(200,ks)
L4=Label(a,text='你好!',font=('黑体',16))
L4.place(x=x,y=20)
b1=Button(a,text='开始',command=f)
b1.place(x=100,y=50)
b2=Button(a,text='停止',command=tz)
b2.place(x=200,y=50)