您的位置:首页 > 编程语言 > Python开发

Python图形化模块:Tkinter

2015-11-29 12:56 791 查看
参考资料:http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html

python版本:2.7.10

操作系统:MAC OX yosemite

Tkinter版本:8.1

基本使用:

import Tkinter as tk

class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()

def createWidgets(self):
self.quitButton = tk.Button(self, text="Quit", command=self.quit)
self.quitButton.grid()

app = Application()
app.master.title('My APP')
app.mainloop()

这里command参数是设置动作,比如我们可以自己定义(def)一个方法printHello,然后command=printHello,这样在点击这个Button时,就会调用我们的printHello方法,完成我们需要的任务。

geometry(),是设置窗口大小以及定位到屏幕的什么位置。

参数:'wxh+-x+-y'

举例:geometry('300x300+150+200 ')

解释:第一个300是窗口宽,第二个300是窗口高,第三个150是距屏幕左侧距离(这里的+号,也可以用-号,就是向反方向偏移),第四个200是距屏幕顶的距离,单位都是像素。其中宽和高之间使用字母x连接(这不是星号,就是字母x),在整个字符串中不能有空格。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Tkinter Python 图形化