文章标题

来源:互联网 发布:c语言实现快速排序 编辑:程序博客网 时间:2024/06/06 09:55

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()
原创粉丝点击