tkinter中spinbox递增和递减控件(十)

spinbox递增和递减控件

 1 import tkinter
 2 
 3 wuya = tkinter.Tk()
 4 wuya.title("wuya")
 5 wuya.geometry("300x200+10+20")
 6 
 7 # 创建一个frame
 8 frm1 = tkinter.Frame(wuya)
 9 frm1.pack(side='left')
10 
11 def func1():
12     text1.delete(0.0,'end')
13     text1.insert('insert',spb1.get())
14 
15 # 创建递增或递减控件,放置在frm1中
16 spb1 = tkinter.Spinbox(frm1,from_=0,to=20,command=func1)
17 # from_为开始的值,to为终止的值
18 spb1.pack()
19 
20 text1 = tkinter.Text(frm1)
21 text1.pack()
22 
23 
24 
25 # 创建一个frame
26 frm2 = tkinter.Frame(wuya)
27 frm2.pack(side='left')
28 
29 def func2():
30     text2.delete(0.0,'end')
31     text2.insert('insert', spb2.get())
32 
33 # 设置递增或递减的值
34 val = ('上海','北京','天津','海南')
35 # 创建递增或递减控件,放置在frm1中
36 spb2 = tkinter.Spinbox(frm2, values=val, increment=1,command=func2)
37 # from_为开始的值,to为终止的值,increment为递增或递减的步长
38 spb2.pack()
39 
40 text2 = tkinter.Text(frm2)
41 text2.pack()
42 
43 wuya.mainloop()

 

结果:

posted @ 2018-04-11 18:42  Tynam.Yang  阅读(269)  评论(0编辑  收藏  举报