专栏名称: python实战
Python实战
目录
相关文章推荐
Python爱好者社区  ·  Beautiful ... ·  4 天前  
Python爱好者社区  ·  36岁当上985高校院长!女教授称“最强大的 ... ·  3 天前  
Python中文社区  ·  拒绝无脑梭哈!用量化信号捕捉行情机会 ·  1 周前  
Python爱好者社区  ·  应届生炒到66.8w年薪,真心建议冲冲这个新 ... ·  1 周前  
51好读  ›  专栏  ›  python实战

Python—Tkinter Scale及颜色对画框

python实战  · 公众号  · Python  · 2017-01-24 22:01

正文

SclaeTkinter模块中的通过滑动条来设置数值的一个组件。

tkColorChooser 中的askcolor是颜色选择的对话框。

界面如下:



# coding:utf-8

from Tkinter import *

from tkColorChooser import *

def resize(value):

    label.config(font='Time -%s bold'%value)

def color():

    (x,y)=askcolor()

    label.config(fg=y)

root = Tk()

root.geometry('500x300+300+100')

label = Label(root,text='Python',font='Time 15 bold')

scale = Scale(root,from_=30,to=300,resolution=5,

                 orient=HORIZONTAL,command=resize)

scale.set(12)

button = Button(root,text='color',command=color)

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

scale.pack(fill=X,expand=1)

button.pack()

mainloop()

程序中Scale组件的数值是用来设置Label组件中的python这个单词的大小,color按钮点击后是颜色选择的对话框,通过选择的颜色来设置Python的字体颜色。

认识组件要知道它的参数设置,Scale组件的参数主要有:

orient 方向(默认垂直)  HORIZONTAL水平方向

from_ 最小值 (默认0

to最大值 (默认100

resolution 步长(默认为1)

digits 显示的位数

variable 变量值

command 回调函数