Label Button Scale控件

脚本的功能包括一个resize的回调函数 该函数会议赋予Scale控件。当Scale控件的滑块移动时,这个函数就会被激活,用来调整label控件中文字的大小

# coding=utf-8
import tkinter as tk

def resize(ev=None):
    label.config(font='Helvetica -%d bold' % scale.get())
top = tk.Tk()
top.geometry('250x150')        #定义顶层窗口大小

label = tk.Label(top, text='Hello World', font='Helvetica -12 bold')

label.pack(fill=tk.Y, expand=1)

scale = tk.Scale(top, from_=10, to=40, orient=tk.HORIZONTAL, command=resize)
scale.set(12)
scale.pack(fill=tk.X,expand=1)

quit = tk.Button(top, text='QUIT', command=top.quit, activeforeground='white', activebackground='red')
quit.pack()

tk.mainloop()

 如图所示 当滑块移动时,lael中文字的大小发生变化

原文地址:https://www.cnblogs.com/francischeng/p/9549226.html