python:Tkinter
Tkinter模块是Python的标准Tk GUI工具包接口。
0.示例
from Tkinter import * # 显示一个窗口,有文字label和一个按钮 window = Tk() label = Label(window,text = 'welcom') button = Button(window,text = 'click') label.pack() button.pack() window.mainloop()
from Tkinter import * #点击按钮执行相应的程序 def procOK(): print 'ok' def procCancel(): print 'cancel' window = Tk() btOK = Button(window,text = 'ok',fg = 'blue',command = procOK) btCancel = Button(window,text = 'cancel',fg = 'blue',command = procCancel) btOK.pack() btCancel.pack() window.mainloop()
1.滑动条 Scale
创建一个滑动条:
import Tkinter as tk window = tk.Tk() slider = tk.Scale(window,from_=0,to=100) slider.pack() window.mainloop()
使用滑动条来调节画板的颜色实例:
from Tkinter import * def sliderUpdate(source): #更新参数 red = redSlider.get() green = greenSlider.get() blue = blueSlider.get() color = "#%02x%02x%02x" % (red,green,blue) canvas.config(bg = color) hexText.delete(0,END) hexText.insert(0,color) window = Tk() redSlider = Scale(window,from_=0,to=255,command = sliderUpdate) greenSlider = Scale(window,from_=0,to=255,command = sliderUpdate) blueSlider = Scale(window,from_=0,to=255,command = sliderUpdate) canvas = Canvas(window,width = 200,height = 200) hexText = Entry(window) #创建输入框 #排列这些控件 redSlider.grid(row = 1,column = 1) greenSlider.grid(row = 1,column = 2) blueSlider.grid(row = 1,column = 3) canvas.grid(row = 2,column = 1,columnspan = 3) hexText.grid(row = 3,column = 2) window.mainloop()
------------ 转载请注明出处 ------------