文章标题

python->tkinter->一个聊天界面

不知道这里的.get()和字典的dic.get(key1,key2,·········)是不是一样的

# testGUI_01.py
# 问题1:Text和Frame的Widget标准不同,尝试采用   固定Frame大小      
# 问题1解决:.grid_propagate(0) 固定大小,参数0意义不知->试数->为0时,固定大小,不为0时,不起任何作用
#   .get()的作用及其用法

from tkinter import *
root = Tk()
root.title('hellobook')
def send():   #显示信息
    text2.insert(INSERT,'我:')
    text2.insert(END,text1.get('0.0',END))
    text1.delete('0.0',END)
def happytail():
    text2.insert(INSERT,"the other one:             don't touch me\n")
    text2.insert(END,'\n\t\t\t\t------------爱你哦\n')



# 创建容器
sendframe = Frame(width = 400,height = 100,bg = 'lightgreen')
recordingframe = Frame(width = 400, height = 300 ,bg = 'purple')
buttonframe = Frame(width = 400,height = 30,bg = 'blue')
# 固定容器大小
sendframe.grid_propagate(0)
recordingframe.grid_propagate(0)
buttonframe.grid_propagate(0)

# 创建按钮
button1 = Button(buttonframe,text = "don't click me", command = happytail, width = 12, bg = "red", fg = "white")
button2 = Button(buttonframe,text = "quit", command = root.quit, bg = "blue", fg = "white")
button3 = Button(buttonframe,text = "send", command = send, bg = "red", fg = "white")

# 创建标签
label = Label(root,text = "hello word")

# 创建文本行
text1 = Text(sendframe)
text2 = Text(recordingframe)    


# Frame框架网格布局
sendframe.grid(row = 1,column = 0,columnspan = 3,pady =5,padx = 3)
recordingframe.grid(row = 0,column = 0 ,columnspan = 3,pady = 5,padx =3)
buttonframe.grid(row = 2,column = 0 ,columnspan = 3 ,pady = 2,padx = 3 )

# Button按钮网格布局
button1.grid(row = 2,column = 0)
button2.grid(row = 2,column = 1)
button3.grid(row = 2,column = 2)

label.grid(row = 2, column = 2)

# 文本行文本布局          
# 下面的方法错误,这里没有必要,因为Text 和Frame 的长宽标准不同,所以采用固定大小最有效
# text1.grid(row = 1,column = 0,columnspan = 2,pady = 5,padx =3) 
text1.grid()
text2.grid()
# root的主循环
root.mainloop()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值