【tkinter模块08】Spinbox控件

import tkinter

# 创建主窗口
win = tkinter.Tk()

# 设置标题
win.title('敲你吗')

# 设置大小和位置,前两个x大小 后两个+位置
win.geometry('400x400+500+200')

'''
数值范围控件
increment 每次增加的值
values与from_ to 不能同时使用
'''
# 绑定变量
x = tkinter.StringVar()


def updata():
    print(x.get())


sp = tkinter.Spinbox(win, from_=0, to=100, increment=5, textvariable=x, command=updata)
sp.pack()

sp1 = tkinter.Spinbox(win, values=(0, 2, 4, 6, 8))
sp1.pack()

x.set(20)

print(x.get())

# 进入消息循环
win.mainloop()

发布了96 篇原创文章 · 获赞 103 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_38114487/article/details/104403796