optionmenu选项&scale滑块

OptionMenu选项

OptionMenu(选择项)用来做多选一, 选中的项在顶部显示.

 1 # coding:utf-8
 2 from tkinter import *
 3 root = Tk()
 4 root.geometry('530x300')
 5 
 6 
 7 v = StringVar(root)
 8 v.set('Xujie')
 9 om = OptionMenu(root, v, 'liran', 'Xujie', 'linfeng', 'Anne')
10 om['width'] = 10
11 om.pack()
12 
13 
14 def test01():
15     print('最喜欢的人', v.get())
16 
17 Button(root, text='确定', command=test01).pack()
18 
19 root.mainloop()

 

 Scale滑块

Scale(滑块)用于在指定的数值区间, 通过滑块的移动来选择值

 1 # coding:utf-8
 2 from tkinter import *
 3 root = Tk()
 4 root.geometry('530x200')
 5 
 6 
 7 def text01(value):
 8     print('滑块的值:', value)
 9     newFont = ('黑体', value)
10     a.config(font=newFont)
11 
12 
13 s1 = Scale(root, from_=10, to=50, length=200, tickinterval=5, orient=HORIZONTAL, command=text01)
14 s1.pack()
15 a = Label(root, text='Xujie', width=10, height=1, bg='pink', fg='blue')
16 a.pack()
17 root.mainloop()