import tkinter
import threading
#按F11切换全屏,ESC退出全屏
class FullScreenApp(object):
def __init__(self, master, **kwargs):
self.root = master
# self.tk.attributes('-zoomed', True) # This just maximizes it so we can see the window. It's nothing to do with fullscreen.
self.frame = tkinter.Frame(self.root)
self.frame.pack()
self.state = False
self.root.bind("<F11>", self.toggle_fullscreen)
self.root.bind("<Escape>", self.end_fullscreen)
def toggle_fullscreen(self, event=None):
self.state = not self.state # Just toggling the boolean
self.root.attributes("-fullscreen", self.state)
return "break"
def end_fullscreen(self, event=None):
self.state = False
self.root.attributes("-fullscreen", False)
return "break"
win=tkinter.Tk()
win.title("实时运行窗口")
#根据显示器分辨率自动全屏窗口
w = win.winfo_screenwidth()
h = win.winfo_screenheight()
win.geometry("%dx%d" %(w,h))
win.attributes("-fullscreen",True)
app=FullScreenApp(win)
def fun_timer():
print('hello timer') #打印输出
global timer #定义变量
timer = threading.Timer(2,fun_timer) #60秒调用一次函数
#定时器构造函数主要有2个参数,第一个参数为时间,第二个参数为函数名
timer.start() #启用定时器
timer = threading.Timer(1,fun_timer) #首次启动
timer.start()
cv = tkinter.Canvas(win,background='white')
cv.pack()
cv.create_rectangle(30, 30, 200, 200,
outline='red', # 边框颜色
stipple = 'question', # 填充的位图
fill="red", # 填充颜色
width=5 # 边框宽度
)
cv.create_oval(240, 30, 330, 200,
outline='yellow', # 边框颜色
fill='pink', # 填充颜色
width=4 # 边框宽度
)
cv.create_rectangle(50, 20, 150, 80, fill="#476042")
cv.create_rectangle(65, 35, 135, 65, fill="yellow")
cv.create_line(0, 0, 50, 20, fill="#476042", width=3)
cv.create_line(0, 100, 50, 80, fill="#476042", width=3)
cv.create_line(150,20, 200, 0, fill="#476042", width=3)
cv.create_line(150, 80, 200, 100, fill="#476042", width=3)
cv.create_text(60,40,text= "hi, i am string", font = "time 10 bold underline", tags = "string")
points = [100, 140, 110, 110, 140, 100, 110, 90, 100, 60, 90, 90, 60, 100, 90, 110]
cv.create_polygon(points, outline="#476042",
fill='yellow', width=3)
#img = tkinter.PhotoImage(file="1.jpg")
#cv.create_image(20,20, image=img)
label = tkinter.Label(win,text = '爷来了')
label.pack()
# win:父窗体
# text:显示的文本内容
# bg:背景色
# fg:字体颜色
# font:字体
# wraplength:指定text文本中多宽之后换行
# justify:设置换行后的对齐方式
# anchor:位置 n北,e东,w西,s南,center居中;还可以写在一起:ne东北方向
label = tkinter.Label(win,
text="this is a word",
bg="pink", fg="red",
font=("黑体", 20),
width=20,
height=10,
wraplength=100,
justify="left",
anchor="ne")
# 显示出来
label.pack()
li = ['C','python','php','html','SQL','java']
movie = ['CSS','jQuery','Bootstrap']
listb = tkinter.Listbox(win) # 创建两个列表组件
listb2 = tkinter.Listbox(win)
for item in li: # 第一个小部件插入数据
listb.insert(0,item)
for item in movie: # 第二个小部件插入数据
listb2.insert(0,item)
listb.pack() # 将小部件放置到主窗口中
listb2.pack()
label1 = tkinter.Label(win, text="柳多妍", bg="pink")
label2 = tkinter.Label(win, text="多多", bg="yellow")
label3 = tkinter.Label(win, text="超级飞侠", bg="red")
# label1.pack() # #默认没有布局,字有多长,背景也有多长,和其他label错落显示
# label2.pack()
# label3.pack()
label1.place(x=10, y=10) # #固定坐标,按绝对布局显示,窗口大小的变化对布局没有影响
label2.place(x=50, y=50)
label3.place(x=100, y=100)
label1.config(text="NEW")
win.mainloop()