tkinter第一章

tk1

------------------------------------------------------------------------------------------

import tkinter as tk

#app是一个Tk(界面)类
app = tk.Tk()
app.title("标题")

 

#the label是一个Label类
theLabel = tk.Label(app,text="我的第一个标签")#建立一个label类
theLabel.pack()

app.mainloop()

 

------------------------------------------------------------------------------------------

 

tk2

------------------------------------------------------------------------------------------

import tkinter as tk


class APP:#写一个窗口
def __init__(self,master):
frame = tk.Frame(master)#框架类,起到分类的作用
#frame.pack()#自动调整位置
frame.pack(side =tk.LEFT,padx=10,pady=10 )#调整为左边的位置 padx:x轴的间距 pady :y轴的间距

 


#按钮类,内容为text fg:前景色 ,command:触发方法 bg:背景色
self.hi_there = tk.Button(frame,text="打招呼",fg="blue",bg="green",command=self.say_hi)
self.hi_there.pack()#自动调整位置

def say_hi(self):#触发button按钮
print("我在打招呼")


root = tk.Tk()#root 相当于雕刻的原木

app = APP(root)#APP这个类 相当于雕饰的过程

root.mainloop()#让这个艺术品运行起来

 

------------------------------------------------------------------------------------------

 

posted @ 2017-08-25 09:42  半臻  阅读(243)  评论(0编辑  收藏  举报