原文
1. 安装python
click here to download
双击安装(我用的是3.5.1版本)
2. 运行脚本
创建 trinker.py
写以下代码
双击运行代码
3. 入门
1 2 3 4 5 6 7
| import tkinter root = tkinter.Tk() root.mainloop()
|
4. 窗口参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| root['bg'] = 'black' root['cursor'] = 'abc.png' root['bd'] = '2' root['height'] = '400' root['padx'] = '10' root['pady'] = '10' root['width'] = '400' root['menu'] = myMenu
|
5. 窗口函数
1 2 3 4 5 6 7 8 9 10
| root.title("this is a window created with tkinter in python") root.geometry('600x500+10+20'); root.resizable(width=True,height=False) root.iconbitmap('gif/003.ico') root.mainloop()
|
7. 几何布局之pack
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| elem.pack(**options) pack_configure() pack_forget() pack_info() pack_propagate(flag) pack_slaves() anchor = center,x,e,nw,ne,se,sw,s,n expand = True,false fill = none,both,x,y in = ipadx = 0 ipady = 0 padx = 0 pady = 0 side = left,right,top,bottom
|
7. 几何布局之grid
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| elem.grid(**options) grid_slaves(row = 'none', column = 'none') grid_size() elem.grid_rowconfigure(index, **options) grid_columnconfigure(index, **options) girid_propagate(flag) True,False grid_location(x, y) grid_info() grid_forget() grid_configure(**options) [ grid_bbox(column=None, row=None, col2=None, row2=None) column = 1 row = 2 columnspan = 2 rowspan = 3 in = in_ = ipadx = ipady = padx = pady = sticky = w,e,n,s,se,we,ne,nw
|
7. 几何布局之place
1 2 3 4 5 6 7 8 9 10 11
| elem.place(**options) place_configure(**options) place_forget() place_info() place_slaves() Same as place_slaves. slaves()
|
8. 常用颜色定义
bg: 背景颜色
fg:前景颜色
activebackground: 当widget是活跃widget的背景颜色.
activeforeground:小部件时,部件是活跃的前景色.
background: widget的背景颜色。这也可以代表ASBG.
disabledforeground: 前景色的部件,当部件被禁用.
foreground: widget的前景色。这也可以表示为FG.
highlightbackground: 部件具有焦点时的亮点区域的背景颜色.
highlightcolor: 前景色的亮点区域,部件具有焦点时.
selectbackground: widget的所选项目的背景颜色.
selectforeground: 前景色为widget的选定项目.