码迷,mamicode.com
首页 > 其他好文 > 详细

tkinter第一章1

时间:2017-08-25 10:59:47      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:过程   界面   艺术品   自动   com   roo   框架类   标题   imp   

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()#让这个艺术品运行起来

 

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

 

tkinter第一章1

标签:过程   界面   艺术品   自动   com   roo   框架类   标题   imp   

原文地址:http://www.cnblogs.com/banzhen/p/7426531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!