Tkinter 是 Python 的标准 GUI (Graphic User Interface)库。Python 使用 Tkinter 可以快速的创建 GUI 应用程序。
由于 Tkinter 内置到 python 的安装包中,只要安装好 Python 之后就能 import Tkinter 库。python 回调函数
import Tkinter
top = Tkinter.Tk()
top.mainloop()
这里介绍一下mainloop。
mainloop就是进入到事件(消息)循环。一旦检测到事件,就刷新组件。
譬如你输入一个字符,就要立即在光标那个位置显示出来(前提是你选中了文本框,也就是鼠标在文本框这个图案的范围内单击过)。
运行结果:


from Tkinter import *
root = Tk()
computerLanguages = ['C','C++','Python','Java']
humanLanguages = ['Chinese','English','Spanish']
listbox1 = Listbox(root)
listbox2 = Listbox(root)
for item in computerLanguages:
listbox1.insert(0,item)
for item in humanLanguages:
listbox2.insert(0,item)
listbox1.pack()
listbox2.pack()
root.mainloop()
运行结果:

from Tkinter import *
def clickButton():
print('hello button')
root = Tk()
Button(root, text='MyButton', command = clickButton).pack()
root.mainloop()
说明:
这里的clickButton是一个回调函数。当你点击按扭的时候,回调函数会被调用,在终端里打印出“hello button”。
运行结果:



Tkinter的提供各种控件,如按钮,标签和文本框等。
目前有15种Tkinter控件。下表作了简单的介绍:
控件 描述
滚动条控件,当内容超过可视化区域时使用,如列表框。python 回调函数.
标准属性也就是所有控件的共同属性,如大小,字体和颜色等。
属性 描述
Tkinter控件有特定的几何状态管理方法,管理整个控件区域组织,一下是Tkinter公开的几何管理类:包、网格、位置
几何方法 描述
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-84956-1.html
可我去不了
这个人还是教授吗
骗来