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()
截圖: