Python内建GUI模块Tkinter(二)

Python核心组件

范例:

1 import Tkinter as tk
2 import os,datetime
3 def create_windows(fun):
4   def only_windows():
5     windows = tk.Tk()
6     windows.title("ryan")
7     windows.resizable(1,1) 
8     windows.geometry("200x200")
9     windows.update()
10     fun(windows)
11     windows.mainloop()
12   return only_windows
13 @create_windows
14 def decorate_fun(windows):
15   in_put = tk.Entry(windows)
16   in_put.pack()
17   out_put = tk.Text(windows,height=4)
18   out_put.pack()
19   def inner_put():
20     var = in_put.get()
21     files = eval(var)
22     out_put.delete("1.0",tk.END)
23     out_put.insert("insert", files)
24     click_button = tk.Button(windows,text="insert",command=inner_put)
25     click_button.pack()
26 decorate_fun()

 <br>

1、Button 按钮组件:一个简单的按钮,用来执行一个命令或别的操作。

参数解析:

  text:指定按钮上显示的文本;

  anchor: 指定按钮上文本的位置(N, NE, E, SE, S, SW, W, NW, or CENTER);

  borderwidth(bd): 指定按钮边框的宽度;

  foreground(fg): 指定按钮的前景色;

  background(bg): 指定按钮的背景色;

  activeforeground: 按下时前景色

  activebackground: 按下时背景色

  font: 指定按钮上文本的字体;

  height: 指定按钮的高度;

  width: 指定按钮的宽度

  command: 指定按钮消息的回调函数;

  cursor: 指定鼠标移动到按钮上的指针样式(heart,dot,cross,plus,spider,star);

  state: 指定按钮的状态(disabled,normal,active);

2、Radiobutton 单选框:代表一个变量,它可以有多个值中的一个。点击它将为这个变量设置值,并且清除与这同一变量相关的其它radiobutton。

参数解析:

  anchor: 文本位置;

  background(bg): 背景色; 

  foreground(fg): 前景色;

  borderwidth: 边框宽度;

  width: 组件的宽度; 

  height: 组件高度;

  bitmap: 组件中的位图;

  image: 组件中的图片;

  font: 字体;

  justify: 组件中多行文本的对齐方式;

  text: 指定组件的文本;

  value: 指定组件被选中中关联变量的值;

  variable: 指定组件所关联的变量;

  indicatoron: 特殊控制参数,当为0时,组件会被绘制成按钮形式;       

  textvariable: 可变文本显示,与StringVar等配合着用

猜你喜欢

转载自www.cnblogs.com/windyrainy/p/10622992.html