1 # GUI:tkinter使用 2 # 通过调节滚动条改变标签中字体大小 3 import tkinter as tk 4 5 6 def resize(ev=None): 7 '''改变label字体大小''' 8 label.config(font='Helvetica -%d bold' % scale.get()) 9 10 11 top = tk.Tk() # 实例化tkinter对象 12 top.geometry('250x150') # 设置窗口大小 13 top.title('滑动设置') # 设置窗口标题 14 15 # Label控件 16 label = tk.Label(top, text='Hello World', font='Helvetica -12 bold') 17 label.pack(fill=tk.Y, expand=1) 18 19 # scale滚动条,数值从10到40,水平滑动,回调resize函数 20 scale = tk.Scale(top, from_=10, to=40, orient=tk.HORIZONTAL, command=resize) 21 scale.set(25) # 设置初始值 22 scale.pack(fill=tk.X, expand=1) 23 24 # Button控件 25 quit_btn = tk.Button(top, text='QUIT', command=top.quit, 26 activeforeground='white', activebackground='red') 27 quit_btn.pack() 28 29 tk.mainloop()
截图: