python中Tkinter模块

label

from tkinter import *

root = Tk()  
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()  #进入消息循环
#控件的显示步骤:
#1.创建这个控件  
#2.指定这个空间的master,即这个控件属于哪一个  
#3.告诉GM(geometry manager)有一个控件产生了






   from Tkinter import * root = Tk()  
    #左对齐,文本居中  
    Label(root,text = 'welcome to jcodeer.cublog.cn',bg = 'yellow',width = 40,height = 3,wraplength = 80,justify = 'left').pack()
     #居中对齐,文本居左 
     Label(root,text = 'welcome to jcodeer.cublog.cn',bg = 'red',width = 40,height = 3,wraplength = 80,anchor = 'w').pack() 
    #居中对齐,文本居右  
    Label(root,text = 'welcome to jcodeer.cublog.cn',bg = 'blue',width = 40,height = 3,wraplength = 80,anchor = 'e').pack()  
 root.mainloop()





   label = Label(root,fg = 'red',bg = '#FF00FF',text = 'Hello I am Tkinter')

参数: fg:前景颜色
bg:背景颜色
width:宽
height:高


button

from Tkinter import * #定义Button的回调函数  
def helloButton():      
    print ('hello button') 
root = Tk()  
#通过command属性来指定Button的回调函数  
Button(root,text = 'Hello Button',command = helloButton).pack()
root.mainloop() 
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值